【问题标题】:Can't kill cpulimit via psutil无法通过 psutil 杀死 cpulimit
【发布时间】:2018-12-11 15:24:49
【问题描述】:

我通过 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 时会出现杀死问题(外壳被杀死而不是它的孩子),但我不这样做。

【问题讨论】:

    标签: python python-3.x kill psutil


    【解决方案1】:

    我目前的解决方法是

    cpulimit.kill()                          # stop the execution
    del cpulimit                             # terminate the process
    dd.send_signal(psutil.signal.SIGCONT)    # restore full CPU usage
    

    然而,为什么psutil 的杀戮与终端的杀戮不同,我们仍不清楚。

    【讨论】:

      猜你喜欢
      • 2012-08-16
      • 1970-01-01
      • 2016-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多