python3杀死进程,杀死python3.X中的所有进程和线程
发布日期:2021-10-31 15:52:50 浏览次数:5 分类:技术文章

本文共 1308 字,大约阅读时间需要 4 分钟。

I'm writing a UI wrapper for reading some info using esptool.py

I have two active threads: UI and procesing - SerialReader.

UI class has reference to the SerialReader and should stop SerialReader when it gets the exit command.

The problem is that I call esptool command which gets stuck in trying to read data over serial connection.

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()

What I want is to kill all active process of this program. When I call close the UI and call serialReaderProcess.stop() it doesn't stop the process. I can see the output of esptool on the console.

I don't care if I interrupt anything, no data can be corrupted.

I've tried sys.exit(0) to no avail.

I've researched the problem but couldn't find a solution.

The OS is Ubuntu and I don't care about cross-platform features, but they would be nice

解决方案

As stated in comments, setting the thread as Daemon solved the problem:

super().__init__(daemon=True)

Daemon threads are automatically killed when the program quits.

转载地址:https://blog.csdn.net/weixin_39987847/article/details/118830940 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:皖西学院计算机协会组织部,皖西学院
下一篇:职称计算机考试 数量,职称计算机考试WPS基础考点:自动求和

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月25日 13时04分35秒