【发布时间】:2020-07-13 09:44:20
【问题描述】:
我正在编写一个 UI 包装器,用于使用 esptool.py 读取一些信息
我有两个活动线程:UI 和处理 - SerialReader。 UI 类引用了 SerialReader,当它收到退出命令时应该停止 SerialReader。
问题是我调用了 esptool 命令,它在尝试通过串行连接读取数据时卡住了。
class SerialReaderProcess(threading.Thread):
def __init__(self, window):
super().__init__()
self.window = window
self.logger = window.logger
self.window.set_thread(self)
self._stop_event = threading.Event()
def run(self):
...
#read chip id
esptool.main(['chip_id'])
...
def stop(self):
self._stop_event.set()
def stopped(self):
return self._stop_event.is_set()
我想要的是杀死这个程序的所有活动进程。当我调用关闭 UI 并调用 serialReaderProcess.stop() 时,它不会停止该过程。我可以在控制台上看到 esptool 的输出。
我不在乎我是否中断任何东西,不会损坏任何数据。
我试过sys.exit(0) 无济于事。
我已经研究过这个问题,但找不到解决方案。
操作系统是 Ubuntu,我不关心跨平台功能,但它们会很好
【问题讨论】:
-
更改为
super().__init__(daemon=True),阅读Daemon Threads Explanation
标签: python-3.x multithreading ubuntu kill