views:

266

answers:

2

I have a automated process using python/paramiko anf have this error:

Exception in thread Thread-1 (most likely raised during interpreter 
shutdown)

....
....
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 
'error'

I understand that is a problem in the cleanup/threading, but not see how fix it...

I have the last version (1.7.6) and according to http://groups.google.com/group/comp.lang.python/browse%5Fthread/thread/6f0dab88bbcca6cf was solved, so I download the code directly but still get it.

Fail on python2.6/python2.5 under winxp/win2003.

I close the connection in the __del__ destructor, close it before finish the script but none of both works. Is more, using this the error happened earlier, so maybe is not related to interpreter shutdown??

+1  A: 

__del__ is not a deconstructor. It's called when you delete a object's last name, which doesn't nessesarily happen when you exit the interpreter.

Anything that manages a context, such as connections, is a context manager For example there is closing:

with closing(make_connection()) as conn:
    dostuff()

# conn.close() is called by the `with`

Anyways, this exception happens because you have a daemonic thread that is still trying to do it's work while the interpreter is already shutting down.

I think you can only fix this by writing code that stops all running threads before exiting.

THC4k
And exist a deconstructor on python 2.5+??? Or how clean the threads, how know? Sorry, but in this case I'm newbie
mamcx
A: 

Close your connections in the normal program control flow, not in __del__, as @THC4k said, it's not a deconstructor, and in general, you shouldn't need to use __del__ (of course there are exceptions).

If you're creating your own threads, you need to .setDaemon(True) if you want them to exit normally when the main thread exits.

JimB