python - 以有限的优先级启动子进程

标签 python windows python-3.x subprocess

我正在寻找一种方法来使用系统优先级较低的 Pythons subprocess 模块启动进程,我已经找到了:

subprocess manual 中没有提及priority .

我已经有了似乎有效的解决方案:

self.start_low_priority =  ('cmd', '/c', 'start', '/MIN', '/LOW', '/B', '/WAIT')

注意: 开关 /B/WAIT 必须按此顺序才能工作

并将其用作:

args = self.start_low_priority + ( 'foo.exe', 'bar', 'foobar')
subprocess.call( args, shell=False)

但是这个解决方案似乎不是正确和干净的方式加上Process Explorer无法从这样启动的应用程序构建正确的“进程树”(因此您无法杀死进程树)。

Windows 有什么好的做法吗? Python 没有为此提供任何我错过的多平台解决方案吗?

最佳答案

您可以使用 psutil图书馆。 特别是您可以将优先级设置 psutil.Process.nice 设置为所需的值。

另见 this回答一个例子。


编辑:直接查看psutil的文档设置Process.nice已被弃用,您应该使用Process.nice (值) 代替。

关于python - 以有限的优先级启动子进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13799371/

相关文章:

python - 使用 Python 检查字节字符串是否以特殊字符结尾

python - django.db.utils.IntegrityError : column "color_set_id" contains null values

python - urllib.request.urlopen 返回字节,但我无法对其进行解码

windows - 相当于 Windows 上的 'cut'

python - 将整数转换为 python 中的字节字符表示时的性能

python - 列表中每个单词的平均字符数

用于流式传输请求正文内容的 Python 服务器

windows - 运行批处理脚本时如何最小化命令提示符?

python - 拟合后如何获取lmfit参数呢?

python - 按小时过滤 DataFrame 行