views:

57

answers:

3

Hello,

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.

+1  A: 

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
wump
A `for` loop would be simpler. `for i in {1..1000}` or `for ((i=0; i<1000; i++))` or in the Bourne shell: `for i in $(seq 1000)`
Dennis Williamson
+2  A: 

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.

Noufal Ibrahim
+2  A: 

As a one-liner, in Bash:

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