Seven, process

 Operating system background

  As the name implies, a process that is the process of being executed, the process is an abstraction of a running program

  The concept originated in the process of the operating system, is the core concept of the operating system, the operating system also provides one of the oldest and most important abstractions of the operating system are all other content around the concept of the process unfolded, so to understand process, understand the operating system must be implemented

  PS: Even if you can only use a cpu (early computer is true), but also to ensure the ability to support the (pseudo) concurrently, to a separate programming multiple virtual cpu cpu (multi-channel technology: Event Multiplexer and spatial multiplexing isolation hardware + support), there is no process of abstraction, modern computers will cease to exist

  The necessary theoretical basis:

  The role of the operating system:

  Hide ugly complex hardware interface, providing good abstract interface

  Management, scheduling processes, and multiple processes competing hardware becomes orderly

  Multi-channel technology:

  Background: For single-core, concurrency

  ps: Typically, the host is now a multi-core, each core will use multi-channel technology

  There are four cpu, io encountered obstruction to run a program cpu1, and io will wait until the end of the re-adjustment, it will be dispatched to any of the four cpu in a specific decision by the operating system scheduling algorithm

  Spatial multiplexing: the memory as multiple concurrent channel programs

  Multiplexing in time: a time-multiplexed slice of cpu

  

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  In the process python program operation

  multiprocess module: multiprocess is not a module but a pack operation, management process in python

  multiprocess.process module

  process module Introduction

  process module is a module process of creating, by means of this module, you can complete the process of creating

Process ([group [, target [ , name [, args [, kwargs]]]]]), the object of this class is instantiated obtained indicate a sub-task process (not yet started) 

emphasized:
 1 . Requires the use of a key word means of development parameter
 2 .args specified for the target location parameter passed to the function, is a tuple form, there must be a comma 

parameters introduced:
 1 .group parameter is not used, the value is always None
 2 represents the calling object .target, That process executes subtask
 3.args object position parameter indicates that the call tuple, args = (1,2, ' Egon ' ,)
 4.kwargs indicates that the call object dictionary, kwargs = { ' name ' : ' Egon ' , ' Age ' : 18 is }
 . 5 .name as the name of the child process

 . 1 .p.start (): start process and the child process calls p.run ()
 2.p.run (): method of operation, when the process starts, it is the function to call the specified target, we custom classes must be achieved in the method
 3 .p.terminate (): Forced to terminate the process P, not will perform any clean-up operation, if p create a child process, the child process to become a zombie process, particularly the use of this method requires 
careful this case, if p then also saved a lock will not be released, which led to the death lock
 4 .p.is_alive (): If p is still running and returns True
 5 .p.join ([timeout]): p wait for the main thread to terminate (stressed: the state is the main thread in the other, and p is in a state run ), timeout is optional timeout 
should be emphasized that, p.join can join live start open process, and can not join the live run open process

 1 .p.daemon: the default value is False, if set to True , on behalf of p is running in the background daemon when to terminate the parent process p, p also will be terminated, and after setting True, 
p can not create its own process, must () before setting the p.start
 2 .p .name: name of the process
 3 .p.pid: process pid
 4 .p.exitcode: identity test process Key, the default is a string of 32 characters randomly generated, the key is to use inter-process relates to the underlying network connection by os.urandom () 
to provide secure communications, such links only when the same authentication key specific success (to understand)

In the windows operating system because there is no fork (mechanism to create a process of linux operating system), when creating the child process will automatically import start it this document, and in the 
import when they execute the entire file, so if the process ( ) written directly in the file will create a child process infinite recursion error, it is necessary to create a child process of partial 
use if__name__ == ' __main__ ' judgment protected, import time will not run recursively    

  Create a process using a process module

  Open sub-process in a python process, start method and concurrent effect

 

Guess you like

Origin www.cnblogs.com/blogbo/p/11798436.html