Aydin Abiar
Aydin Abiar

Reputation: 374

Run a script in parallel until another one finishes

I have 2 python scripts A.py and B.py

I'd like to run both of them in parallel, but I'd like to keep running B.py multiple times successively in parallel until A.py finishes

something like :

A.py &
while A.py not finished :
     B.py &
end while

I'm very bad at shell scripting, can someone explain me how to do this ?

Thank you in advance

Upvotes: 1

Views: 510

Answers (1)

dan
dan

Reputation: 5231

You can use this loop:

#!/bin/bash

python A.py &

while [[ $(jobs -pr) ]]; do
    python B.py
done

jobs -pr lists the process IDs (-p) of running jobs (-r). If the output is empty, the backgrounds command has finished.

Upvotes: 2

Related Questions