Python multi-Threading concurrent Processing module-threading

Source: Internet
Author: User

Thread: Multithreading of the underlying support module, generally not recommended to use;

Threading: Thread is encapsulated, some threads of the operation of the object, the general use of this method to achieve multithreaded programming


There are two modes of multithreaded implementations:

1. Create a function to execute the thread and pass the function into the thread object

2. Inherit directly from threading and create a new class,


Threading module:

Threading. Important functions of the thread class

Threading.currentthread (): Returns the current thread variable.

Threading.enumerate (): Returns a list that contains the running thread. Running refers to threads that do not include pre-and post-termination threads until after the thread has started and ends.

Threading.activecount (): Returns the number of running threads with the same result as Len (Threading.enumerate ()).


The start () method initiates thread activity

The is_alive () or IsAlive () method returns whether the thread is active or not.

Setdaemon () method

Isdaemon () method

The run () method is used to represent thread activity

The GetName () method returns the name of the thread

SetName () method to set the thread name

The join ([Time]) method waits until the thread aborts. This blocks the calling thread until the thread's join () method is called abort-gracefully exits or throws an unhandled exception-or an optional timeout occurs





This article is from the "mask_x blog" blog, please be sure to keep this source http://zhpfbk.blog.51cto.com/4757027/1886549

Python multi-Threading concurrent Processing module-threading

Related Article

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.