title: Python, Windows, and Multiprocessing
body: <p>I have a Python program originally built on and for Linux, which I'm now trying to port over to Windows. I am running the program in a virtual environment which contains all of the dependencies (my program is installed as a wheel with pip install --find-links wheels my_module). The program is launched with</p>
  
  <pre><code>(venv) C:\&gt;venv\Scripts\python.exe -m base_module.Launcher arg1 arg2
  </code></pre>
  
  <p>The base_module loads my module as interpreted by the arguments provided, and his relevant code is:</p>
  
  <pre><code>from multiprocessing.managers import SyncManager
  import OtherCustomClass
  
  class BaseModule(object):
      def __init__(self, arg1, arg2):
          self.manager = SyncManager()
          self.manager.start(ignore_interrupt)
  
  def main(argv=None):
      ret = -1
      try:
          basmod = BaseModule(argv[0], argv[1])
          ret = basmod.run()
      except Exception, err:
          print("error: " + str(err))
          print(traceback.format_exc())
      return ret
  
  if __name__ == "__main__":
      exitCode = main(sys.argv[1:])
      sys.exit(exitCode)
  </code></pre>
  
  <p>This has worked fine in Linux, but on Windows I get the following exception:</p>
  
  <pre><code>Traceback (most recent call last):
      File "&lt;string&gt;", line 1, in &lt;module&gt;
      File "C:\Python27\Lib\multiprocessing\forking.py", line 380, in main
        prepare(preparation_data)
      File "C:\Python27\Lib\multiprocessing\forking.py", line 505, in prepare
        '__parents_main__', file, path_name, etc
      File "build/bdist.linux-x86_64/egg/base_module/BaseModule.py", line 2, in &lt;module&gt;
  ImportError: No module named OtherCustomClass
  exception in main:
  Traceback (most recent call last):
      File "build/bdist.linux-x86_64/egg/base_module/BaseModule.py", line 12, in main
      File "build/bdist.linux-x86_64/egg/base_module/BaseModule.py", line 7, in __init__
      File "C:\Python27\Lib\multiprocessing\managers.py", line 528, in start
          self._address = reader.recv()
  EOFError
  </code></pre>
  
  <p>The latter EOFError is caused by the unexpected early termination from the forking in SyncManager, where the true error is being unable to import OtherCustomClass.  I have confirmed that OtherCustomClass exists in the base_module's folder within venv/lib/site-packages, and this error isn't happening when I launch the module first as Python would never reach the instructions in main() or <strong>init</strong> if the script wouldn't compile.</p>
  
  <p>I've done some research, and I know this problem has hit other people (often using third party libraries, who fixed the issue without posting the solution). It seems to trace back to Windows' lack of a fork(), and python's handling of multiprocessing on Windows - see also <a href="http://docs.python.org/library/multiprocessing.html#windows" rel="nofollow">http://docs.python.org/library/multiprocessing.html#windows</a>. But I'm at a loss as to how to fix this.</p>
  
  <p>This is the latest Python 2.7 branch (2.7.8), running on Windows 7 x64.</p>