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

Re: [pygame] SOC Proposal: Networking for Pygame



On Tue, 2006-05-09 at 10:19 -0500, Bryce Allen wrote:
> I think using a separate thread is the best approach. Are most Pygame API 
> calls thread safe? Most importantly, is pygame.event.post(e) thread safe?

Yes, the SDL event queue is fully thread safe, and so is Pygame code on
top of it. (Although if you are coding in C you will likely need to grab
the Python GIL to post custom events on the queue)

> How this is done is another issue. The event queue could be emulated, which 
> may be fairly easy since we already have to buffer events to avoid 
> overflowing the SDL queue. 

There are two main strategies I can think of, it may depend on the type
of game. First is simple blocked networking calls. This way the server
is idle while waiting for network data.

The other would be some sort of "get_all_events" nonblocking call where
the server could operate at a fixed framerate.