gpt4 book ai didi

Python 超时脚本杀死线程事件超过 X 秒

转载 作者:太空狗 更新时间:2023-10-29 19:28:46 26 4
gpt4 key购买 nike

我一直在到处寻找一个好的超时脚本,如果线程处于事件状态超过 X 秒,它可以终止线程,但我看到的所有示例都存在并不总是会停止线程的缺陷。使用 thread.join(x) 最终违背了它成为线程的目的。

我找到的唯一像样的例子是 Timeout on a function call而那个也不是没有缺陷..

有人知道更好的方法吗?

最佳答案

请参阅我对 python: how to send packets in multi thread and then the thread kill itself 的回答- 有一个带有 InterruptableThread 类的片段和在超时后杀死另一个线程的示例 - 正是您想要的。

还有类似的Python recipe在激活状态。

关于Python 超时脚本杀死线程事件超过 X 秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/811692/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com