title: os.waitpid() seems not working properly
body: <p>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.</p>
  <h3>pseudo code showing here</h3>
  <h3>the actual code is longer and working:</h3>
  <pre><code>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+'(&quot;' + bam + ')&quot;') 
      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)
  </code></pre>
  <p>note: eval will return a string, which is a command for the &quot;run&quot; function</p>
  <p>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)</p>
  <p>Can anyone spot any bug in the code?
  Many thanks!</p>