python process

Original: https://www.cnblogs.com/LY-C/p/9145729.html

Use process module may create a process

multiprocessing Import Process from 
the p-Process = (target, args, name) 
target: the calling object representation that the process of sub-tasks to be performed 
args: indicates the position of the object parameter called "tuple" 
name: name of the process

  method

p.start (): to start the process, the system decides when to call p.run () 
p.run (): Now running processes 
p.terminate (): p forcibly terminate the process, will not carry out any cleaning operation, if p is created child process, the child process to become a zombie process, this method requires special care this situation. If p then also saved a lock will not be released, leading to a deadlock 
p.is_alive (): determine whether there is a process p, if p is still running and returns True 
p.join ([timeout]): Let the master wait for the child process is finished (stressed: the state is the main thread in the other, and p is in a state of operation). 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  

  Attributes

p.daemon: The default value is False, if set to True, the representative of p is a daemon running in the background, when the termination of the parent process p, p also will be terminated, and after setting True, you can not create your own new p the process must be set before p.start () 
p.name: process name 
p.pid: process pid

  Examples

Process multiprocessing Import from 
Import Time 

DEF FUNC (name): 
    Print ( 'name is Son S%'% name) 
    the time.sleep (. 5) 
    Print ( 'here Son') 

IF the __name__ == '__main__': 
    P = Process (target = FUNC, args = ( 'xxx',)) 
    p.start () 
    the time.sleep (2) 
    p.join () # code execution to be here, waiting for the main course main stop child process is finished before continuing to 
    print ( 'this is Father')

  

 

Guess you like

Origin www.cnblogs.com/forlive/p/11592264.html