Solving thread cleanup on paramiko

爱⌒轻易说出口 提交于 2019-12-01 03:07:33
Jochen Ritzel

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

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.

I now, is not the case. But a find this discussion, searching a problem whit my wxpython app.

Solve it to add a close event to the main frame. So all the thread's will be close.

class MyFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        super(MyFrame, self).__init__(*args, **kwargs)

        # Attributes
        self.panel = MainPanel(self)

        # Setup
        path = os.path.abspath("./comix.png")
        icon = wx.Icon(path, wx.BITMAP_TYPE_PNG)
        self.SetIcon(icon)

        # Layout
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.panel, 1, wx.EXPAND)
        self.SetSizer(sizer)

        self.CreateStatusBar()
        # Event Handlers
        self.Bind(wx.EVT_CLOSE, self.OnClose)

   def OnClose(self, event):
        ssh.close()
        winssh.close()
        event.Skip()

I hope this cant help to anyone.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!