Solving thread cleanup on paramiko

前端 未结 3 1968
时光取名叫无心
时光取名叫无心 2021-01-11 16:02

I have an automated process using paramiko and have this error:

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

....
....
<         


        
3条回答
  •  甜味超标
    2021-01-11 16:51

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

提交回复
热议问题