Reputation: 4101
I'm writing a multi threaded Python app that makes many TCP connections to servers. Each connection is done on a separate thread. Sometimes the thread hangs for a long time which I don't want. How can I get the thread to kill itself after some given time period? From the main thread how can I determine that the child thread killed itself?
If possible I would appreciate a snippet of code showing how to do this. Thanks.
Update The system is Ubuntu 9:10
Upvotes: 7
Views: 9267
Reputation: 851
Short answer: Just make the def run() end. So, if you are waiting for data from a socket, do it with timeout, then if timeout occur just break the while that you should have, and the thread will be killed.
You can check from main thread if a thread is alive with isAlive() method.
Upvotes: 5