您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python多处理模块:超时连接过程

Python多处理模块:超时连接过程

您可以通过创建一个循环来完成此操作,该循环将等待一些超时时间,并经常检查所有进程是否已完成。如果它们还没有在指定的时间内完成,请终止所有过程:

TIMEOUT = 5 
start = time.time()
while time.time() - start <= TIMEOUT:
    if not any(p.is_alive() for p in procs):
        # All the processes are done, break Now.
        break

    time.sleep(.1)  # Just to avoid hogging the cpu
else:
    # We only enter this if we didn't 'break' above.
    print("timed out, killing all processes")
    for p in procs:
        p.terminate()
        p.join()
python 2022/1/1 18:41:45 有279人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶