Process method attribute summary

Process method
     1.p.start ()         # boot process 
    2.p.run ()          # method of operation, when the process starts, it is to call the target function specified custom class must implement this method 
    3.p.terminate ()     # forcibly terminate the process p, will not carry out any cleaning operation, if p create a child process, the child process to become a zombie process. If p then also saved a lock will not be released, leading to a deadlock 
    4.p.is_alive ()     # If p is still running and returns True 
    5.p.join ()         # main thread waits for termination of p, p. join can only join live start open process, and can not join the live run open process
    
Process properties
    1.p.daemon         # The default is False, if set to True, the representative for the p * * 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 p his new process must be set in p.start () before 
    2.p.name         # name of the process 
    3.p.pid             # process pid 
    4.p.exitcode      # process at runtime None 
    5.p.authkey         # the process of authentication keys
    
* * Daemon :
     1 . Code Execution of the parent process ends, the daemon is over
     2 are not allowed to open sub-processes.
     3 if not join, if daemon is the last position in the parent process code, then the parent process has no code. , so the daemon will not be able to perform.
# ###################################### simple example     
from multiprocessing Import Process
 Import Time
 DEF FUNC ( ):
    time.sleep(1)
    print(123)
if __name__ == '__main__':
    p = Process(target=func,)
    p.start()
    p.terminate () # kill process p, let the interpreter tells the operating system, please kill the p process. 
    Print ( ' the child was still alive? ' , p.is_alive ())
    the time.sleep ( 0.002 )
     Print ( ' the child was still alive? ' , p.is_alive ())
     # returns a bool value, if it returns True, the representative of the process is still alive, if it returns False, the representative of the child dead

# P.is_alive () to determine whether the process is still alive p 
# p.terminate () to kill the p process

 

Guess you like

Origin www.cnblogs.com/god-for-speed/p/11719080.html