Daemon (daemon) process introduced:
The join () method can cause a process to run and then execute the next process, and the daemon () method will not wait for the child process to terminate the child process immediately after the execution of the main process's code is finished.
Both the join () method and the daemon () method are methods that change the order of the processes.
Characteristics:
The 1.daemon () method is written before the start () method.
2. Once the child process is set up as a daemon, the child process terminates immediately once the main process code is executed, regardless of whether the child process has finished running.
code example:
1 fromMultiprocessingImportProcess2 ImportOs,time,random3 deftask ():4 Print('runing', Os.getpid ())5Time.sleep (Random.randint (1,3))6 Print(' Done', Os.getpid ())7 if __name__=='__main__':8P1 = Process (target=Task)9P1.daemon = True#set P1 as a daemonTen P1.start () One Print('Main Process', Os.getpid ())
Daemons vs Daemon Threads