Terminating threaded programs

mk mrkafk at gmail.com
Thu Feb 11 15:17:54 EST 2010


Stephen Hansen wrote:
> I use threads all the time (well, for certain types of workloads) and 
> have never seen this.
> 
> Are your threads daemon threads? The only time I've seen sys.exit() not 
> close out my program is when I'm launching non-daemon threads on accident.

The snag is that my program is using calls to another threaded library 
(paramiko) which does lots of stuff with sockets and communication 
(SSH). Paramiko in turn calls Crypto which has compiled C extensions. I 
really don't know what's going on in there, just guessing that this 
might trigger this behavior.

> Now, I do get some slightly random errors on close due to threads doing 
> stuff or returning from doing stuff while the shutdown procedure is 
> going on, but I don't really care, cuz, well, I'm shutting everything 
> down and nothing worth knowing is going on in the rest of the program.

Same as me, except I get lots of exceptions in threads if I shut down 
with sys.exit. SIGTERM somehow gets around this problem.

I'll try os._exit.

Regards,
mk




More information about the Python-list mailing list