title: Python multiprocessing pool, join; not waiting to go on?
body: <p>(1) I'm trying to use <code>pool.map</code> followed by <code>pool.join()</code>, but python doesn't seem to be waiting for <code>pool.map</code> to finish before going on past the <code>pool.join()</code>. Here's a simple example of what I've tried:</p>
  
  <pre><code>from multiprocessing import Pool
  
  foo = {1: []}
  
  def f(x):
      foo[1].append(x)
      print foo
  
  def main():
      pool = Pool()
      pool.map(f, range(100))
      pool.close()
      pool.join()
      print foo
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>The printed output is just <code>{1: []}</code>, as if python just ignored the <code>join</code> command and ran <code>print foo</code> before it had a chance to run <code>f</code>. The intended result is that <code>foo</code> is <code>{1:[0,1,...,99]}</code>, and using the ordinary built-in python <code>map</code> gives this result. Why is the pooled version printing <code>{1: []}</code>, and how can I change my code to make it print the intended result? </p>
  
  <p>(2) Ideally I'd also like to define <code>foo</code> as a local variable in <code>main()</code> and pass it to <code>f</code>,
  but doing this by making <code>foo</code> the first argument of <code>f</code> and using</p>
  
  <p><code>pool.map(functools.partial(f, foo), range(100))</code></p>
  
  <p>produces the same output. (and possibly also has the problem that each process now has its own copy of <code>foo</code>?) Though again, it works using the normal <code>map</code> instead.</p>