我正在为我的 GUI 使用 wxPython。在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
?)涉及,但我真的不明白发生了什么。有人对此有更深入的了解吗?那太好了!