Python multi-thread creation threads

Source: Internet
Author: User
' Create thread ' from threading import thread# defines a function def Foo (ARG): Print (ARG) #创建一个线程对象, and establishes a relationship with the function Foo above, args= Pass a value of 100 as parameter to the Foo function print ("Start creating thread ...") T1 = Thread (target=foo,args= ()) t2 = Thread (target=foo,args= (200,)) # Before execution, which thread is T1.setdaemon (True) #执行线程print ("Execution thread ...") T1.start () T2.start () #直到该线程执行完后才继续往下执行, which can pass in a value (number), Set the wait Time T1.join () #查看是否等子线程结束后主线程才退出的设置, the default value is false to indicate that it is not the main thread, meaning that it will wait until the child thread finishes executing, and the main line friend exit print (T1.isdaemon ()) Print ( T2.isdaemon ()) #查看线程的名字, the SetName () method is to set the thread's name print (T1.getname ()) print (T2.getname ())


This article is from the "Q Group: 223843163" blog, please be sure to keep this source http://freshair.blog.51cto.com/8272891/1896634

Python multi-thread creation 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.