在 Python 中,join
函数用于等待当前线程终止,可以用于阻塞当前线程,直到调用该函数的线程终止。
例如,如果你有一个 MyThread
类:
import threading
class MyThread(threading.Thread):
def run(self):
# 运行代码
...
thread = MyThread()
thread.start()
# 阻塞当前线程,直到 `thread` 线程终止
thread.join()
在上面的代码中,在调用 thread.start()
后,线程会在