Daemons vs Daemon Threads

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.