title: Python Multiprocessing Doesnt Terminate On Base Exception
body: <p>When running using multiprocessing pool, I find that the worker process keeps running past a point where an exception is thrown.</p>
  
  <p>Consider the following code:</p>
  
  <pre><code>import multiprocessing
  
  
  def worker(x):
      print("input: " + x)
      y = x + "_output"
      raise Exception("foobar")
      print("output: " + y)
      return(y)
  
  
  def main():
  
      data = [str(x) for x in range(4)]
      pool = multiprocessing.Pool(1)
      chunksize = 1
      results = pool.map(worker, data, chunksize)
      pool.close()
      pool.join()
  
      print("Printing results:")
      print(results)
  
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>$ python multiprocessing_fail.py
  input: 0
  input: 1
  input: 2
  Traceback (most recent call last):
  input: 3
    File "multiprocessing_fail.py", line 25, in &lt;module&gt;
      main()
    File "multiprocessing_fail.py", line 16, in main
      results = pool.map(worker, data, 1)
    File "/usr/lib/python2.7/multiprocessing/pool.py", line 251, in map
      return self.map_async(func, iterable, chunksize).get()
    File "/usr/lib/python2.7/multiprocessing/pool.py", line 558, in get
      raise self._value
  Exception: foobar
  </code></pre>
  
  <p>As you can see, the worker process never proceeds beyond <code>raise Exception("foobar")</code> to the second print statement. However, it resumes work at the beginning of function worker() again and again.</p>
  
  <p>I looked for an explanation in the documentation, but couldn't find any. Here is a potentially related SO question:</p>
  
  <p><a href="https://stackoverflow.com/questions/1408356/keyboard-interrupts-with-pythons-multiprocessing-pool">Keyboard Interrupts with python&#39;s multiprocessing Pool</a></p>
  
  <p>But that is different (about keyboard interrupts not being picked by the master process).</p>
  
  <p>Another SO question:</p>
  
  <p><a href="https://stackoverflow.com/questions/22094852/how-to-catch-exceptions-in-workers-in-multiprocessing">How to catch exceptions in workers in Multiprocessing</a></p>
  
  <p>This question is also different, since in it the master process doesnt catch any exception, whereas here the master did catch the exception (line 16). More importantly, in that question the worker did not run past an exception (there is only one executable line for the worker). </p>
  
  <p>Am running python 2.7</p>