pygame.event.post_event should work in multi-threaded code

Issue #324 resolved
Diez Roggisch
created an issue

When working e.g. on the raspberry PI, you can't always avoid multi-threading because of the way GPIOs are handled on that platform.

The SDL documentation of SDL_PushEvent explicitly states that it's multi-thread safe.

However, the current implementation of event.post_event checks for pygame.init() being called unconditionally when posting from another thread. I'm not an SDL expert, and got to work around things by invoking "pygame.init()" once when hitting that thread first.

This should happen "magically" behind the curtains.

Comments (2)

  1. René Dudfield

    You should just be able to call pygame.init() once in your program, not in every thread. Are you doing this? Maybe a minimal example code showing the issue would help me understand it better.

    You may want to check out fastevent module. Which works better when posting events from other threads.

  2. Diez Roggisch reporter

    After trying to come up with a minimal example, I found out that the actual cause was ar race condition! Sorry for the noise, but maybe it serves as cautionary tale :)

  3. Log in to comment