I have three functions (two loops) defined in such a way that i want to process a chunk of file from command_1 through command_3, once finished, go back process another chunk using the same work flow.
pseudo code showing here
the actual code is longer and working:
def run(cmd):
try:
subprocess.Popen(command,shell='True')
except:
exit()
def run_chunk(chunk,command,flag=False)
for file in chunk
cmd = eval(command+'("' + bam + ')"')
run(cmd)
def main():
chunks = [[chunk1],[chunk2]...]
for chunk in chunks:
run_chunk(chunk, command_1, True)
os.waitpid(-1,0)
run_chunk(chunk, command_2, True)
os.waitpid(-1,0)
run_chunk(chunk, command_3, True)
os.waitpid(-1,0)
note: eval will return a string, which is a command for the "run" function
my problem is that, when i run command_1, os.waitpid() seems working; once command_1 finishes, the program goes to command_2, it seems to me that command_2 will wait itself before goes to command_3, but the outer loop in the main function will execute command_1 immediately (which i do not wanted)
Can anyone spot any bug in the code? Many thanks!