title: Python parallel execution - threading.Lock not working as intentioned
body: <p>I currently have a global <code>Lock = threading.Lock()</code>, and make the following call:</p>
  
  <pre><code>Parallel(n_jobs=2)(delayed(serialRemove)(dir,c,b,l,f) for f in os.listdir(dir))
  </code></pre>
  
  <p>using jobLib. In <code>serialRemove</code>, I have</p>
  
  <pre><code>Lock.acquire()
  print(f+' begin')
  if h in hashes:
      try:
          os.remove(path)
          if l: print('Removing ' + path)
          removed += 1
      except os.error:
          print('Encountered error removing file') 
  else:
      hashes.add(h)
  print(f+' end')
  Lock.release()
  </code></pre>
  
  <p>Part of the call results in:<br/>
  10.txt begin<br/>
  11.txt begin<br/>
  20.txt begin<br/>
  I don't understand how there could be two begin prints if I surround the code in a Lock. Is there any easy way to protect the code block so ideally I get:<br/>
  10.txt begin<br/>
  10.txt end<br/>
  11.txt begin<br/>
  11.txt end<br/>
  20.txt begin<br/>
  20.txt end<br/></p>