Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Running multiple python scripts sequentially with nohup

requests=(25 50 75 100)
factors=(3 6)
graphsizes=(25 50 75)

for request in "${requests[@]}" 
do
  for factor in "${factors[@]}"
  do
    for size in "${graphsizes[@]}"
    do
        echo "Now Running: n = ${request}, factor = ${factor}, size = ${size}" >> nohup.out
        nohup python3 -u main.py "$request" 50 "$factor" "$size" > ${request}_${factor}_${size}.log 
        echo "Done Running: n = ${request}, factor = ${factor}, size = ${size}" >> nohup.out
    done
  done
done

My intention: I want to run all the various permutation of arguments to main.py sequentially; i.e., print Now Running..., then call nohup and run the python script, when that is done print Done running...

Note that I cannot add a & at the end of the nohup line, since that would make the script proceed before main.py has finished.

However, by not using the &, I can no longer use the current shell process while this script is running. Is there any way to get around this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

What you probably want, is the following: remove the nohup from the commands in your shell script, but run the overarching script that you show here (i.e., all the code; let’s call it iterations.bash with nohup and in the background: nohup bash iterations.bash >& iterations.log &. Now you have your command line back, while the processes inside the script are run sequentially.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading