开发者

How to wait for a list of threads to finish? (Python)

开发者 https://www.devze.com 2023-03-21 11:48 出处:网络
For a single thread, I would do thread.join(60) threadEvent.set() How can I make it wait for all threads in the list to开发者_如何转开发 finish OR wait until the timeout and then issue the set() to

For a single thread, I would do

thread.join(60)
threadEvent.set()

How can I make it wait for all threads in the list to开发者_如何转开发 finish OR wait until the timeout and then issue the set() to the threading.Event()? Each thread has a corresponding threading.Event() that will be used to stop the thread. The important part is that if the timeout is reached, I need to set the event for each thread.


import time
endTime = time.time() + 60
for t in threads:
    t.join(endTime - time.time())
    t.event.set()
0

精彩评论

暂无评论...
验证码 换一张
取 消