The join function of the threading module in Python

Source: Internet
Author: User

The role of join is well known, blocking the process until the thread finishes executing. The common practice is that we start a batch of threads and finally join these threads to the end, for example:

1  forIinchRange (10):2 3t =threadtest (i)4 5 thread_arr.append (t)6 7  forIinchRange (10):8 9 Thread_arr[i].start ()Ten  One  forIinchRange (10): A  -Thread_arr[i].join ()

The principle of join here is to verify that threads in the thread pool end in turn, block until the end of the thread, and then jump to execute the join function of the next thread if it ends.

The join function of the PY also has a special function that can set the timeout, as follows:

Thread.Join ([timeout])

Wait until the thread terminates. This blocks the calling thread until the thread whose join () method was called Terminates–either normally or through an U Nhandled Exception–or until the optional timeout occurs.

That is, by passing a parameter to the join to set the timeout, that is, the join is not blocking the process over the specified time. In the actual application of the test, it is found that not all the threads end in the time-out period, but the order of the execution of the test is timed out in time_out time, for example, the time-out is set to 2s, the previous thread in the absence of the completion of the case, A subsequent thread execution join sets a 2s timeout from the end of the previous thread.

The join function of the threading module in Python

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.