Kill stuck threads

Rhodri James rhodri at
Tue Apr 9 09:29:11 EDT 2019

On 09/04/2019 14:08, Shakti Kumar wrote:
> Over due course I've felt the need of a way to kill a thread gracefully, by
> relieving all occupied resources.
> A bit of search online shows me that killing a thread depends very much on
> the underlying platform support, and is something not advised, however I
> face this problem when one of my devices don't respond and my code keeps
> waiting indefinitely for an SSH reply.

Fundamentally, don't do that.  Never let a thread wait indefinitely on 
something you don't have control over.  Use timeouts, and think hard 
about your recovery strategies.

Killing and restarting a thread is always going to be a risky business, 
and will leave your system less stable.  Don't do it unless you have no 
choice (and if you think you have no choice, you're probably wrong!).

Rhodri James *-* Kynesim Ltd

More information about the Python-list mailing list