Python Threading Module

Source: Internet
Author: User

#-*-coding:utf-8-*-__author__ = ' magicpwn ' import threadingimport timeimport queuedef worker (): Print Threading.curren  T_thread (). GetName () def worker2 (): For I in Range (0,1000): Print I time.sleep (1) threads = []for I In range (5): T = Threading. Thread (target=worker) #新创建线程, specifies the execution of a function, Threads.append (t) t.start () s = Threading. Thread (Target=worker2, args= ()) # daemon Thread daemon is set to true then it is a non-critical thread, and the main path does not wait for its end to end on the process. # set to False or default indicates the thread is important and the main thread waits for it to end before the process can be ended. # The daemon thread means that by default, or when the child thread Setdaemon (False) is set, the # main thread becomes the daemon thread of the child thread. When all threads end, the main thread ends the process. S.setdaemon (False) threads.append (s) s.start ()


This article is from the "Magicpwn" blog, make sure to keep this source http://magicpwn.blog.51cto.com/10497784/1683820

Python Threading Module

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.