I am calling a shell (.sh) script from my python code and I want to tell Python to wait for the script to end before continuing to the rest of the code. For the record, the script is calling a HPC cluster some calculations which take approximately 40-50min. I could probably do sleep()
and force python to wait for these 40-50min, but firstly I do not always know the amount of time that should wait, and secondly I was hoping for a more efficient way of doing this.
So, the script is called by using os.system("bsub < test.sh")
.
Is there any way to actually tell python wait until the script is finished and then continue with the rest of the code? Thanks in advance
I think @Barmar identifies the problem in a few comments
When you run bsub
, it submits the job and immediately returns, rather than waiting for completion.
You should either
-K
arg to bsub for it to wait refbsub
and run the script directly