【发布时间】:2012-11-27 18:33:20
【问题描述】:
我正在寻找一种方法如何使用具有低系统优先级的 Pythons subprocess 模块启动进程,我已经找到了:
-
solution for
Unix使用preexec_fn和os.nice() -
resourcesmodule 似乎又只适用于Unix - some another questions and answers for linux
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 没有为此提供任何我错过的多平台解决方案吗?
【问题讨论】:
标签: python windows python-3.x subprocess