我通过Python的psutil
执行一个进程,它负责繁重的负载。因此,我通过cpulimit
限制了它的CPU使用。
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
的全部CPU使用率。
我知道在psutil.Popen
中使用shell=True
时的杀死问题(外壳被杀死,而不是它的子级),但我不这样做。
发布于 2018-12-12 10:23:39
我目前的解决方法是
cpulimit.kill() # stop the execution
del cpulimit # terminate the process
dd.send_signal(psutil.signal.SIGCONT) # restore full CPU usage
然而,它仍然不清楚为什么psutil
的杀死不同于终端的杀死。
https://stackoverflow.com/questions/53727273
复制相似问题