所以基本上我有一个类,比如SerialClass,它创建一个本地线程来更新一个combobox,构造函数如下所示:
def __init__(self, master):
...
# Local thread.
self.__thread = threading.Thread(target=self.__thread_handler)
self.__thread_finished = False
self.__thread.start()
这是线程执行的函数,它只是用值更新组合框。在
^{pr2}$这是我用来退出线程的函数:
def thread_exit(self):
self.__thread_finished = True
self.__thread.join()
另一个类,比如App,实例化了SerialClass类。App创建一个Tk对象并使用以下方法启动主应用程序:
def run(self):
# Handle the close window event.
self.__root.protocol("WM_DELETE_WINDOW", self.__on_close)
# Start the application and wait for user events.
self.__root.mainloop()
这是一种“打开关闭”方法:
def __on_close(self):
# When the application finishes, handle the rest of the threads.
self.__serialui.thread_exit()
# Destroy the root window as expected.
self.__root.destroy()
我遇到的问题是程序流从未到达根目录。销毁()函数,由于某些原因,当我调用thread_exit函数时,主线程永远被阻塞。如果我评论self.update_端口()在thread_handler函数中,所有进程都优雅地关闭。在
有什么想法吗?在
目前没有回答
相关问题 更多 >
编程相关推荐