Terminating threaded programs

ssteinerX@gmail.com ssteinerx at gmail.com
Thu Feb 11 13:57:29 EST 2010


On Feb 11, 2010, at 11:43 AM, Aahz wrote:

> In article <mailman.1961.1265383809.28905.python-list at python.org>,
> mk  <mrkafk at gmail.com> wrote:
>> 
>> I have a problem with a threaded program: it frequently hangs on sys.exit.
>> 
>> The problem is that my program uses threads which in turn use paramiko 
>> library, which itself is threaded.
>> 
>> I try to gracefully close the threads (below), but it doesn't always 
>> work, if paramiko calls happen to be at stage of negotiating ssh 
>> connection or smth similar.
>> 
>> The only workable solution I have is a program sending itself SIGKILL, 
>> which makes it terminated by OS (I think so).
> 
> You can also use os._exit().

This just came up on the Twisted IRC channel last night and came to the same conclusion.  Python's going to wait for threads to terminate and if they're not going to, neither is Python.  os._exit() came up as the 'last resort' way out of the app.

S




More information about the Python-list mailing list