title: Python multiprocessing - How to break from a map efficiently?
body: <p>Breaking from a <code>map</code> works as expected:</p>
  
  <pre><code>def worker(x):
      print("worker call x=%s" % x)
      return x
  
  for x in map(worker, range(5)):
      print(x)
      if x == 2:
          break
  
  worker call x=0
  0
  worker call x=1
  1
  worker call x=2
  2
  </code></pre>
  
  <p>But if I do the same with <code>multiprocessing</code>, I get this:</p>
  
  <pre><code>from multiprocessing import Pool
  
  pool = Pool(2)
  for x in pool.map(worker, range(5)):
      print(x)
      if x == 2:
          break
  pool.close()
  pool.join()
  
  0
  1
  2
  worker call x=0
  worker call x=1
  worker call x=2
  worker call x=3
  worker call x=4
  </code></pre>
  
  <p>Why is multiprocessing's map behaving differently? How to avoid the unnecessary function calls?</p>