title: Python, Multiprocessing: what does process.join() do?
body: <pre><code>import time
  from multiprocessing import Process
  
  def loop(limit):
      for i in xrange(limit):
          pass
      print i
  
  limit = 100000000 #100 million
  
  start = time.time()    
  
  for i in xrange(5):
      p = Process(target=loop, args=(limit,))
      p.start()
  p.join()
  
  end = time.time()
  print end - start
  </code></pre>
  
  <p>I tried running this code, this is the output I am getting</p>
  
  <pre><code>99999999
  99999999
  2.73401999474
  99999999
  99999999
  99999999
  </code></pre>
  
  <p>and sometimes</p>
  
  <pre><code>99999999
  99999999
  3.72434902191
  99999999
  99999999
  99999999
  99999999
  99999999
  </code></pre>
  
  <p>In this case the loop function is called 7 times instead of 5. Why this strange behaviour?</p>
  
  <p>I am also confused about the role of the <code>p.join()</code> statement. Is it ending any one process or all of them at the same time?</p>