Solving thread cleanup on paramiko

paramiko, python, ssh

Solution

`__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.

Problem

I have an automated process using paramiko and 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 I don't know how to fix it. I have the latest version (1.7.6) and according to this thread, it was solved, so I download the code directly but still get the error. The failure occurs on Python 2.5/2.6 under winxp/win2003. I close the connection in the `__del__` destructor, then close it before the end of the script, none of which works. Is there more, using this the error happened earlier, so maybe is not related to interpreter shutdown??

Original source

Related problems