Python超时 [英] Python Timeout

查看:86
本文介绍了Python超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直到处寻找一个好的超时脚本,如果该脚本处于活动状态超过X秒钟,该脚本可以杀死该线程,但是我所看到的所有示例都存在无法始终停止该线程的缺陷. .使用thread.join(x)最终会破坏它成为线程的目的.

I've been looking all over the place for a good timeout script that can kill a thread if it's been active for more than X seconds, but all the examples I've seen have flaws that don't always stop the thread. Using thread.join(x) ends up defeating the purpose of it being a thread.

我发现的唯一不错的示例是函数调用超时并非没有缺陷.

The only decent example I've found is Timeout on a function call and that one's not without its flaws..

有人知道这样做的更好方法吗?

Anyone know of a better way to do this?

推荐答案

请参阅我对

See my answer to python: how to send packets in multi thread and then the thread kill itself - there is a fragment with InterruptableThread class and example that kill another thread after timeout - exactly what you want.

在活动状态下,也有类似的 Python食谱.

There is also similar Python recipe at activestate.

这篇关于Python超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆