Usage of python thread object join

A code

import threading
import time
def func1(x, y):
    for i in range(x, y):
        print(i, end=' ')
    print()
    time.sleep(10)
t1=threading.Thread(target = func1, args = (15, 20))
t1.start()
t1.join(5)
t2=threading.Thread(target = func1, args = (5, 10))
t2.start()
#t2.join() #the program will not continue until t2 thread finishs
print(t1.isAlive())
time.sleep(2) #try to comment this line to see the different result
print(t2.isAlive())

 

Two running results
E:\python\python can learn this way\Chapter 13 Multithreading and Multiprocess Programming\code>python SecondExample.py
15 16 17 18 19
5 6 7 8 9
True
True

Intelligent Recommendation

Usage of Java thread join ()

The role of join () method is to wait for this thread to end; In other words, the t.join () method blocks the calling thread from entering the TIMED_WAITING state until the thread t completes, and the...

Usage of thread join

MSDN:Blocks the calling thread until a thread terminates 1. What is the calling thread? 2. What is a thread?   Run a program, that is, start a process and at least one thread,Threads, not process...

Join usage and cases in Thread

Join usage and cases in Thread There are two threads A, declared as a, and thread B, declared as b. If thread A executes the b.join() method, its meaning is that the current thread A waits for the ter...

Thread expansion (JOIN usage)

Let's take a look at a picture: How to make the execution right of the current thread Yield () method, only in the JDK some internal implementation can be seen, let the execution right, basically not ...

Thread wait, join usage

1. Wait stop thread, wait for the notification, you need to lock it with objects, and use this object notify when you need to continue the thread 2. Join cut into line, the other thread is running, I ...

More Recommendation

Thread-usage of Join (), usage of yield ()

1 join void join()   Wait for the thread to terminate. (1) Case 1: The t1.join () method is between the t1.start () and t2.start () methods: t1.join () tells the main thread t1 thread to join the ex...

Usage of Python multi-thread and multi-process Join and daemon

Daemon process: The main process code is finished, and the daemon process ends (the main process is the daemon) Daemon thread: The non-daemon thread code finishes running, and the daemon thread ends (...

[Python] Quick use of Threading and understanding of thread locks and the usage of .join() in detail

0X0: Before we start, understand the meaning of threading. We know that we write a program, and then the program will run and get the desired result. This is my understanding of a software. Then somet...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top