[paramiko] transport threads not shutting down

Dwayne Litzenberger dwayne at oscl.ca
Wed Mar 19 09:45:26 PDT 2008


There are three ways to close a transport:

1. transport.close()
2. __del__
3. atexit

If you're using #2 or #3, it's more-or-less known Python behaviour (see 
http://www.thescripts.com/forum/thread41024.html).  There are ways of 
modifying the code so that it doesn't happen, but it could possibly take a 
lot of work and make the code a lot uglier (it involves avoiding the use of 
_any_ globals in code paths that might be called from __del__ or atexit).  As 
a rule, you shouldn't rely on the garbage collector to take care of cleaning 
up threads and other complicated tasks.

#1 should always work properly, though.

Could you build a test script that we can use to reproduce this problem?


On March 19, 2008 10:27:56 am Justin Cook wrote:
> I've tried both ways. When the program exits, the classes __del__
> method closes the transport. I've even tried atexit handling it. It's
> not every time. Just sometimes this happens. Just weird why the socket
> module would be destroyed while the thread is still running.
>
> On Wed, Mar 19, 2008 at 4:20 PM, Dwayne Litzenberger <dwayne at oscl.ca> wrote:
> > On March 18, 2008 10:30:05 am Justin Cook wrote:
> >  > After calling transport.close(), it appears the transport threads are
> >  > not stopping in a timely manner.
> >
> >  Are you explicitly calling transport.close() during normal program
> > execution, or is this during __del__  or atexit processing?


-- 
Dwayne Litzenberger, B.A.Sc.
Information Technology Analyst

Open Systems Canada Limited
#210 - 2332 11th Ave
Regina, SK S4P0K1
Office: (306) 359-OSCL (6725)
http://www.oscl.ca/



More information about the paramiko mailing list