我使用wxPython的我的GUI。 在AppLogic
类我有一个是在这个类的方法运行工作线程。
这是GUI
类:
class GUI:
_wx_app = None
_main_window = None
_app_logic = None
def start(self):
# bla bla bla
self._main_window.Show()
self._app_logic.begin()
self._wx_app.MainLoop()
def _cancel_listener(self):
"""Called from MainWindow, if the user has clicked the cancel
button."""
print("I'm leaving this scope.")
self._app_logic.cancel() # Should cancel the task done in
# a second thread.
def _status_listener(self, status_text):
"""Called often by the worker thread."""
print("Here I am again.")
if self._main_window.status.GetLabel() != status_text:
self._main_window.status.SetLabel(status_text)
下面是来自取消方法AppLogic
它由所谓类_cancel_listener
从上方:
def cancel(self):
self._shall_abort = True
self._thread.join(self._some_time_out)
assert self._thread.isAlive() == False
不知何故,有一个僵局join
和GetLabel
(因此MainLoop
参与?),但我真的不明白是怎么回事。 是否有人有更深入地了解这一点? 那太好了!