Astro
Astro

Reputation: 11

Print "Jobs Finished" only when all the bjobs are completed

I have a python script that submits multiple jobs using bjobs. Below is the code snippet

 for jobs in job_list:
    i=0
    os.system("bsub -J JOB_{} jobs".format(str(i))
    i+=1

I want to print "Finished runnning" only when all the jobs have completed. How can I do the same ?

Upvotes: 1

Views: 375

Answers (2)

Deadpool
Deadpool

Reputation: 66

you will need to get the result of each job, hence use subprocess module instead.

if you are calling each job on a separate thread, you can use a shared list to for saving the result of each job, so whenever all get done, this list will be the same size as the jobs_list, then you can print the proper message.

but if the code is just the above snippet, you can do this:

for index, job in enumerate(job_list):
    result = subprocess.call(f"bsub -J JOB_{index} jobs")
print("Finished runnning")

Upvotes: 1

KLAS R
KLAS R

Reputation: 62

not sure... but please have a try this !!

counter = 0
for jobs in job_list:
    counter +=1
    i=0
    os.system("bsub -J JOB_{} jobs".format(str(i))
    i+=1
    if len(job_list) <= counter:
        print("Completed")
'''

Upvotes: 0

Related Questions