python - 无法通过 psutil 杀死 cpulimit
问题描述
psutil
我通过负责重负载的 Python 执行一个进程。因此,我通过cpulimit
.
import psutil
dd = psutil.Popen(["dd", "if=/dev/urandom", "of=/dev/zero"])
cpulimit = psutil.Popen(["cpulimit", "-q", "-z", "-p", str(dd.pid), "-l", "10"])
到目前为止,此代码正在运行。但是,我不能杀人cpulimit
。之后我仍然可以在任务管理器中cpulimit.kill()
看到带有进程 ID 的进程。cpulimit.pid
第一次退出该过程del cpulimit
。
此外,与cpulimit
通过终端相比,cpulimit.kill()
也del cpulimit
不会恢复dd
.
我知道使用shell=True
in时的杀戮问题psutil.Popen
(外壳被杀死而不是它的孩子),但我不这样做。
解决方案
我目前的解决方法是
cpulimit.kill() # stop the execution
del cpulimit # terminate the process
dd.send_signal(psutil.signal.SIGCONT) # restore full CPU usage
然而,目前还不清楚为什么psutil
' 的杀戮与终端的杀戮不同。
推荐阅读
- computer-science - 使用固定状态下推自动机
- node.js - 如何通过Postman使用nodejs restAPI计算两个数字的基本和
- eclipse - 在 ESF 模拟器中运行 Hello_Osgi 在 Eclipse EE、Kura、Ubuntu Linux 上崩溃
- firebase - 'package:flutter/src/widget/text.dart':断言失败:第 378 行 pos 10;'data != null':必须向 Text 小部件提供非空字符串
- swift5 - 读取数据时 FileHandler 出现问题
- vue.js - 如何解决 ionic-vue 中的 CROSS Origin 问题?
- mysql - Laravel8 不会对迁移创建外键约束
- gitlab - 通过 API 创建标签或发布时如何防止触发 CI/CD
- here-api - Here API:按距离和按时间等值线之间的缓冲区差异
- java - 从每页itext 7 java的第一段中删除前导