Kill stuck threads

Shakti Kumar shakti.shrivastava13 at gmail.com
Tue Apr 9 09:08:14 EDT 2019


Hello Team,

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.
I figured I could find a way out of the stuck situation by launching a
thread to do the SSH, and raising an exception from main thread if the SSH
thread isn't complete in 20seconds (max time for our devices' login).
But since a Django frontend (for my application) won't kill the stuck
thread, or even the bareminimum python won't, I'm pretty sure I'll run into
resource issue when many users have used the application for non responsive
devices.
I can get around with a timeout value in the pexpect module I'm using for
SSHing, but wanted to check if there's a solution already of getting around
the thread issue.

Best,
Shakti.
-- 
Sent from Shakti’s iPhone



More information about the Python-list mailing list