1
votes

I am trying to use multiprocessing module in python 2.7 to create a gui with wxpython that calls a separate module in a process that will graph things with matplotlib. However Everytime it calls that module, the gui instead just opens a copy of inself. Next I have tried using the multiprocessing module in a simple example. In the IDLE it appears to start the processes fine, but the processes don't actually run. When I run the code from the command line a attributeerror is raised, yet the code works fine when I switch all multiproccessing.Process to threading.Thread

Heres the command line code: http://imgur.com/QuCUWRD

I've tested this module before and it seemed to have worked, so I am probably just doing something silly, however I can't figure out my error at all!

EDIT:

In my GUI changing the line from

queue_thread = multiprocessing.Process(
            target=simple_queue_model.main_func, args = (self.inputs,))

to:

queue_thread = multiprocessing.Process(
            target=simple_queue_model.main_func(self.inputs))

Causes the process to be called, however the main GUI window freezes until the process finishes running, and a new gui window is opened again which I don't understand.

EDIT 2: the previous change just causes my GUI to call main_func no as a separate process. The line queue_thread.start() is what causes a new GUI to spawn, so overall this module isnt working at all for me

1

1 Answers

3
votes

When you start a new process with multiprocessing on Windows, a whole new virgin python process is started, which then imports the various modules you need and passes variables using pickle. In this case, you have defined your functions in the __main__ namespace of the interactive session. To get them to run, save them to a module that y=can be imported from a new process. Be sure to consult the guidelines.

Conversely, threads can share memory and are directly passed the function definitions from the current namespace.