title: Python multiprocessing exit condition error intermittently
body: <p>Multiprocess job is running the tasks, I want to stop the rest of the parallel or dependent tasks if one of them fails or completes all the tasks.
  The problem is with 1st print, where it should check if job failed with non-zero exit code and already not completed then enter the loop and stop the rest of the jobs by breaking the while loop.
  however, even the execution completed successfully with exit 0, it enters the loop intermittently, stops the rest of the jobs by breaking the loop.
  What is going wrong here.
  Failed one
  <a href="https://i.stack.imgur.com/MyNRG.png" rel="nofollow noreferrer">enter image description here</a>
  Passed one
  <a href="https://i.stack.imgur.com/dYtBb.png" rel="nofollow noreferrer">enter image description here</a>
  Main job triggering multiprocess tasks.</p>
  <pre><code>def run_block(index):
      print index
  
      # do some execution
  
  def run_blocks(target, dict_blocks):
      process = []
      for (index, (block_id, depend_on)) in \
          enumerate(dict_blocks.items()):
          proc = multiprocessing.Process(target=run_block, args=index)
          process.append(proc)
          proc.start()
      check_exit(process)
  
  
  def check_exit(process):
      done = False
      process_count = len(process)
      count = 0
      completed = []
      while not done:
          for proc in process:
              if proc.exitcode != 0 and proc.exitcode != None:
                  print ('1st', proc, count, done, proc.exitcode)
                  done = True
                  break
              if proc.exitcode == 0 and proc.pid not in completed:
                  print ('2nd', proc, count, done, proc.exitcode)
                  completed.append(proc.pid)
                  count += 1
              if count == process_count:
                  print ('3rd', proc, count, done)
                  done = True
                  break
      stop_process_exit(process, count, process_count, done)
  
  
  def stop_process_exit(
      process,
      count,
      process_count,
      done,
      ):
      print (process_count, count, done, process)
      for proc in process:
          if proc.is_alive():
              proc.terminate()
      if done == True and count != process_count:
          exit(1)
  </code></pre>