python - 如何等待线程列表完成? (Python)

标签 python multithreading

对于单个线程,我会这样做

thread.join(60)
threadEvent.set()

如何让它等待列表中的所有线程完成或等到超时,然后向 threading.Event() 发出 set() ?每个线程都有一个相应的 threading.Event(),用于停止线程。重要的是,如果达到超时,我需要为每个线程设置事件。

最佳答案

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

关于python - 如何等待线程列表完成? (Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6762891/

相关文章:

python - 将具有重复键的元组列表转换为列表字典

python - 泡泡洗牌 - 加权洗牌

python - 使用多线程python将数据写入文件

multithreading - Perl - 多线程脚本打印内存映射和回溯

c - 适本地存储线程特定变量

python - 网络x : multiple figure with consistent node placement

Python:由于 OSError 无法安装软件包:[Errno 2] 没有这样的文件或目录

python - 在 iPython notebook 中执行 "python setup.py install"

c# - 我在这里正确使用锁吗?我应该尝试用它包装更少的代码吗?

python - 运行开发服务器时,Bottle 框架的线程之一出现 OSError