Can I add pygame events from a second thread
pygame, python, thread-safety
Solution
Time for some detective work!
Looking at the source for `event_post` in event.c indicates that the C function uses the SDL call `SDL_PushEvent`, without checking for thread-safety on its own. However, the documentation for `SDL_PushEvent` says:
This function is thread safe, and can be called from other threads safely.
So it seems that it is indeed thread-safe.
Problem
Well I have read at various places that the pygame event handling must be done in the main thread. I want to do that but my question is, can I add events to the event queue from a different thread? I want to call `pygame.event.post(myEvent)` from a different thread and than handle the event in the main loop. Is this possible? edit: To clarify, I want to run a separate thread for asynchronous network i/o. When a new message arrived the thread would then put an event in the event queue to signal there is something to do.