如何将cpulimit用于python脚本

时间:2016-02-24 07:32:52

标签: python

从我的old question的答案中,我经历了this以及谷歌的更多内容。但我不明白,我怎么能float randomX = Random.Range (-1f,1f); if (randomX < -0.4) { movementX = (-1); } if (randomX > 0.4) { movementX = movementX * -1; } else { movementX = 0; } randomY = Random.Range (-1f,1f); Debug.Log (randomY); if (randomY < -0.4) { movementY = -1; } if (randomY > 0.4) { movementY = 1; } else { movementY = 0; } 得到一个python脚本。 以下是我的尝试:

cpulimit

还有一些......

但在每种情况下都会收到警告:

cpulimit --limit 20 --exe ./read_heavy_csv.py

cpulimit --limit 20 --exe "python read_heavy_csv.py" 

cpulimit -P ./read_heavy_csv.py -l 20

我找不到任何文档来解释使用Warning: no target process found. Waiting for it... 运行python脚本。我也经历了these too,但没有得到任何线索

2 个答案:

答案 0 :(得分:1)

cpulimit不是执行程序,而是限制正在运行的进程的CPU使用率。您需要单独运行该程序。

正常运行程序:

python read_heavy_csv.py

打开其他终端,然后运行以下命令(pgrep ...将为您提供上一个命令的pid)

cpulimit --limit=10 -p `pgrep -f read_heavy_csv\.py`

请注意,pgrep使用RegEx模式,而不是简单的字符串。

答案 1 :(得分:1)

您可以执行以下操作:

cpulimit --limit 50 - python /explicit-path-to-file/extractSift.py start