[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] fork() and PyGame?



Michael wrote:
Does fork()'ing code not work with PyGame? I tried to fork() my application code from the UI code and the events posted by the application code weren't being picked up by the UI. Am I right in thinking that this method just doesn't work or is there something else I'm doing wrong? Thanks.
you'll find fork() is a little extreme for what you want. when you fork your program you create an entirely new process, with its own independent copy of all the program data. the only way the two processes can talk to each other is some form of IPC (socket, sharedmem, etc).

hopefully that's clear enough. it sounds like what you want are separate threads, not forked processes. threads are a little more lightweight, and share all global variables and resources. in this case one thread could read the pygame event queue and another thread do some drawing.

still, you may find the threading more trouble than it's worth. it can lead to many tricky situations that you hadn't even imagined.

since your app has to update the screen once per frame, it makes a lot of sense to just process all the events during that time too. my guess is your ui design has multiple little "main loops" where each ui widget gets control of the app when it has input focus?