【问题标题】:wxpython closing application with threadwxpython用线程关闭应用程序
【发布时间】:2012-10-08 11:25:24
【问题描述】:

大家好,我有点麻烦。 我完成了我的程序,它检查是否存在关于 bitbucket 的新版本。 一切都很好,除了当我关闭我的应用程序并且线程仍在运行时,可以在任务管理器中看到该程序。 EVT_CLOSE的代码如下:

    def on_close(self, event):
    if self._thread is not None and self._thread.isAlive():
        self._thread.interrupt.set()
    self.Destroy()
    event.Skip()

线程像守护进程一样运行。

怎么了?

编辑: 我明白了,我尝试在线程上执行 join() 方法。 但我不工作。

    def on_close(self, event):
if self._thread is not None and self._thread.isAlive():
    self._thread.join()
    self._thread.interrupt.set()
self.Destroy()
event.Skip()

还有:

        def on_close(self, event):
if self._thread is not None and self._thread.isAlive():
    self._thread.join(10)
    self._thread.interrupt.set()
self.Destroy()
event.Skip()

【问题讨论】:

    标签: python multithreading wxpython


    【解决方案1】:

    在您关闭事件处理程序时,您需要让它结束线程或等待线程结束。通常你通过使用线程的 join() 方法来做到这一点。如果线程正在打开另一个进程并且该进程需要很长时间,那么您可能需要尝试终止正在运行的进程以便线程可以返回。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多