title: Python: Multithreaded list append does not work as expected
body: <p>Why is the following code (you can run it <a href="https://repl.it/@CP8/PhonyGlossyKnowledge" rel="nofollow noreferrer">here</a>):</p>
  
  <pre><code>from multiprocessing.pool import Pool
  from time import sleep
  
  MY_LIST = []
  
  
  def worker(j):
      global MY_LIST
      sleep(1)
      MY_LIST.append(j)
      print(j, len(MY_LIST))
  
  
  if __name__ == '__main__':
      parameters= [1, 2, 3, 4]
      with Pool(processes=2) as pool:
          results = pool.map(worker, parameters)
  </code></pre>
  
  <p>prints:</p>
  
  <pre><code>1 1
  2 1
  3 2
  4 2
  </code></pre>
  
  <p>And if I comment out the <code>sleep(1)</code> part, it prints what I expect:</p>
  
  <pre><code>1 1
  2 2
  3 3
  4 4
  </code></pre>
  
  <p>How can I fix the code so that it correctly appends and in the end I have 4 elements in <code>MY_LIST</code></p>