0

I want to execute a 3 separate bash commands on 3 separate core processors of a node of a supercomputer. I have a python script that sends a bash command via os.system to the command line, however it seems to execute the bash command to completion before going to the next line in the python script. I want to just send bash commands to the command line one after another.

 for i in range(0, len(core), 8) :
        os.system("bpsh "+str(1)+" nohup python /home/tree_df_unchuncked.py "+str(' '.join(core[i]))+" 0.01"+" y")
        os.system("bpsh "+str(1)+" nohup python /home/tree_df_unchuncked.py "+str(' '.join(core[i+1]))+" 0.01"+" y")
        os.system("bpsh "+str(1)+" nohup python /home/tree_df_unchuncked.py "+str(' '.join(core[i+2]))+" 0.01"+" y")
l0b0
  • 55,365
  • 30
  • 138
  • 223

2 Answers2

2

Consider building a shell script file from your python program and then executing that shell script. As you build the shell script, place an & at the end of each line. It is also useful to put the wait command at the end of the program so the shell script will pause until all of the background commands (running in parallel) are complete.

#/bin/bash
a &
b &
c &
wait

I could have given you a more specific answer had your code been formatted so that I could copy and paste it and then execute it.

Mark
  • 4,249
  • 1
  • 18
  • 27
0

@Mark is on the right track, but just to explain what is happening: your code isn't doing anything to run the commands in parallel. Ways to do this include, but are not limited to:

l0b0
  • 55,365
  • 30
  • 138
  • 223