1

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.

0

3 Answers 3

7

As a one-liner, in Bash:

for i in {1..1000}; do nohup python test.py & done
Sign up to request clarification or add additional context in comments.

Comments

4

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.

Comments

2

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

1 Comment

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.