Starting multiple instances of a python script at once from linux command line
I'd like to start a piece of python script a thousand times! instead of trying to start them one-by-one how can I do that from linux command line?
Right now, I am doing it like this:
nohup python test.py &
nohup python test.py &
nohup python test.py &
nohup python test.py &开发者_运维知识库;
nohup python test.py &
...
Thanks in advance.
As a one-liner, in Bash:
for i in {1..1000}; do nohup python test.py & done
I would recommend that you keep the spawning logic in a Python program. Perhaps use the multiprocessing
library to do the processes. It'll be hard to manage all of these without some non-trivial scaffolding if you're going to spawn them off in bash.
Simplest is to make a loop using shell script, this will work for anything:
#!/bin/bash
X=0
COUNT=1000
while [ $X -lt $COUNT ]; do
nohup python test.py &
X=$((X+1))
done
精彩评论