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

Python多处理模块:超时连接过程,第1张

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 CPUelse:    # We only enter this if we didn't 'break' above.    print("timed out, killing all processes")    for p in procs:        p.terminate()        p.join()


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5630724.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存