title: Preventing file handle inheritance in multiprocessing lib
body: <p>Using multiprocessing on windows it appears that any open file handles are inherited by spawned processes.  This has the unpleasant side effect of locking them.</p>
  
  <p>I'm interested in either:<br>
  1) Preventing the inheritance<br>
  2) A way to release the file from the spawned process</p>
  
  <p>Consider the following code which works fine on OSX, but crashes on windows at os.rename</p>
  
  <pre><code>from multiprocessing import Process
  import os
  
  kFileA = "a.txt"
  kFileB = "b.txt"
  
  def emptyProcess():
      while 1:
          pass
  
  def main():
      # Open a file and write a message
      testFile = open(kFileA, 'a')
      testFile.write("Message One\n")
  
      # Spawn a process
      p = Process(target=emptyProcess)
      p.start()
  
      # Close the file
      testFile.close()
  
      # This will crash
      # WindowsError: [Error 32] The process cannot access the file
      #               because it is being used by another process
      os.rename(kFileA, kFileB)
  
      testFile = open(kFileA, 'a')
      testFile.write("Message Two\n")
      testFile.close()
  
      p.terminate()
  
  
  if __name__ == "__main__":
      main()
  </code></pre>