title: Python - multiple copies of output when using multiprocessing
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1923706/multiprocessing-launching-too-many-instances-of-python-vm">Multiprocessing launching too many instances of Python VM</a>  </p>
  </blockquote>
  
  
  
  <p>Module run via <code>python myscript.py</code> (not shell input)</p>
  
  <pre><code>import uuid
  import time
  import multiprocessing
  
  
  def sleep_then_write(content):
      time.sleep(5)
      print(content)
  
  if __name__ == '__main__':
      for i in range(15):
          p = multiprocessing.Process(target=sleep_then_write,
                                      args=('Hello World',))
          p.start()
  
  print('Ah, what a hard day of threading...')
  </code></pre>
  
  <p>This script output the following:</p>
  
  <pre><code>Ah, what a hard day of threading...
  Ah, what a hard day of threading...
  Ah, what a hard day of threading...
  Ah, what a hard day of threading...
  Ah, what a hard day of threading...
  Ah, what a hard day of threading...
  Ah, what a hard day of threading...
  Ah, what a hard day of threading...
  Ah, what a hard day of threading...
  AAh, what a hard day of threading..
  h, what a hard day of threading...
  Ah, what a hard day of threading...
  Ah, what a hard day of threading...
  Ah, what a hard day of threading...
  Ah, what a hard day of threading...
  Ah, what a hard day of threading...
  Hello World
  Hello World
  Hello World
  Hello World
  Hello World
  Hello World
  Hello World
  Hello World
  Hello World
  Hello World
  Hello World
  Hello World
  Hello World
  Hello World
  Hello World
  </code></pre>
  
  <p>Firstly, why the heck did it print the bottom statement sixteen times (one for each process) instead of just the one time?</p>
  
  <p>Second, notice the <strong><code>AAh,</code></strong> and <strong><code>h,</code></strong> about half way down; that was the real output. This makes me wary of using threads ever, now.</p>
  
  <p>(Windows XP, Python 2.6.4, Core 2 Duo)</p>