Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Timeout

I have 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 have found is Timeout on a function call and that one is not without its flaws..

Anyone know of a better way to do this?

like image 997
Ian Avatar asked May 01 '09 14:05

Ian


1 Answers

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.

There is also similar Python recipe at activestate.

like image 154
Jiri Avatar answered Oct 01 '22 08:10

Jiri