1

I'm working on a larger size Python application which runs a solver on several hundred distinct problem scenarios. There is a GUI that allows the user to set up the solver configuration. In an attempt to speed this up I have implemented a multiprocessing Pool to spawn new instances of the solver module within the application.

What ends up happening is that during the pool's creation four new copies of the GUI appear, which is entirely not what I'm looking to have happen. I've taken what I thought were the appropriate steps in protecting the entry point of the application as per the programming guidelines but perhaps I've misunderstood something fundamental about the multiprocessing module.

I've followed the guideline in this thread in creating a minimal startup module.

ScenarioSolver.solveOneScenario creates a new instance of the solver and scenarios_to_solve is a list of arguments.

process_pool = multiprocessing.Pool(4)
for _, result in enumerate(process_pool.imap_unordered(ScenarioSolver.solveOneScenario, scenarios_to_solve)):
  self.processResult(result)

So, based on the limited information here, what might I have overlooked in using the Pool?

EDIT: This behavour only happens when I package the application into an executable using py2exe. When running from eclipse I get the intended behaviour.

Community
  • 1
  • 1
circuitBurn
  • 893
  • 11
  • 24

1 Answers1

0

This is the same problem as solved in this thread.

Adding multiprocessing.freeze_support() immediately after if __name__ == '__main__' solved this problem.

Community
  • 1
  • 1
circuitBurn
  • 893
  • 11
  • 24