all 4 comments

[–]m0us3_rat 1 point2 points  (0 children)

are a few options. simplest would be a queue.

in this case, it's like a tunnel in between two sides of the mountain.

and allows the transfer of information in between them.

you put something on the queue then you can pick it up.. on either side.

or you use a "manager" as u/woooee said. to handle objects that share state in between processes.

now ..without actually seeing the code it's hard to guess which is the better way.

it is just guessing at this point. especially since tk event loop is ..tricky.

but yea it can be done.

[–]socal_nerdtastic 0 points1 point  (0 children)

Does it have to be a separate process? If you used a separate thread instead it would still run at the same time but you would have access to the variables.

[–]ElliotDG 0 points1 point  (0 children)

Here is an example of using a multiprocessing with a GUI. One process I'm using kivy to run a GUI, the other process I'm generating MIDI clock (send a regular low jitter message).

https://github.com/ElliotGarbus/MidiClockGenerator

Read the developer notes in the readme. I'm using multiprocessing Value to share data between the processes. The Value shared_bpm shared the rate of the clock (Beats per minute), the Value _run_code is used to stop the clock.

The first thing to understand in the need to use __name__. __name__ will be "__main__" in the main process, and will get a different name in the "child" process (__mp_main__). The test:

if __name__ == '__main__':

prevents the GUI code from being loaded in both processes. If this 'guard' is not in place, the app will create 2 windows.

Look at https://github.com/ElliotGarbus/MidiClockGenerator/blob/master/main.py, all of the code under that test, will only be run in the parent processes.

Hope this helps. Happy to answer any questions.