从linux命令行一次启动python脚本的多个实例

时间:2010-06-21 10:41:19

标签: python linux shell command-line console

我想开始一段python脚本一千次!而不是尝试逐个启动它们如何从linux命令行执行此操作?

现在,我这样做:

nohup python test.py &
nohup python test.py &
nohup python test.py &
nohup python test.py &
nohup python test.py &
...

提前致谢。

3 个答案:

答案 0 :(得分:7)

作为一个单行班,在Bash:

for i in {1..1000}; do nohup python test.py & done

答案 1 :(得分:4)

我建议你将产卵逻辑保存在Python程序中。也许使用multiprocessing库来完成这些过程。如果你打算用bash产生它们,那么如果没有一些非平凡的脚手架,很难管理所有这些。

答案 2 :(得分:2)

最简单的方法是使用shell脚本进行循环,这适用于任何事情:

#!/bin/bash
X=0
COUNT=1000
while [ $X -lt $COUNT ]; do
    nohup python test.py &
    X=$((X+1))
done