title: Python: terminate all alive processes based on an exception type
body: <p>Using multiprocessing Process object, how do we terminate all alive processes when an exception occurred in one of them?</p>
  
  <pre><code>from multiprocessing import Process
  from time import sleep
  
  def func(i):
     print 'begin', i
     sleep(i)
     if i == 3:
        raise Exception
     print 'end', i
  
  def terminate_all(procs):
     for p in procs:
        if p.is_alive():
           p.terminate()
  
  processes = []
  for i in range(0,10):
      p = Process(target=func, args=(i,))
      processes.append(p)
      p.start() # where do I catch the Exception and call terminate_all?
  
  
  for p in processes:
      p.join()
  </code></pre>