Concurrent Programming daemon

Create a master daemon process

  First: the daemon will terminate after the end of the main process code execution

  Second: within daemon can no longer turn a child process, otherwise it throws an exception: AssertionError: daemonic processes are not allowed to have children

Note: the process is independent of each other, the main process code to finish, daemons immediately terminated

import multiprocessing
import time

def taks_one():
    print("zi run")
    time.sleep(3)
    print("zi over")

if __name__ == '__main__':
    print("父 start")
    p = multiprocessing.Process(target=taks_one)
    p.daemon = True     # 在进程开启前,设置守护进程
    p.start()
    time.sleep(5)
    print("父 over")

In the above code, it is equivalent to the master daemon process, the child process equivalent daemon

Guess you like

Origin www.cnblogs.com/plf-Jack/p/11130243.html