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

Re: [pygame] Threads




On Apr 17, 2005, at 9:33 PM, Bob Ippolito wrote:

One way would be to run anoher thread which peeks at the sdl event
queue for twisted events, and then runs the iterateTwisted function.
However it looks like sdl events are not thread safe according to
this.    http://www.gameprogrammer.com/fastevents/fastevents1.html
Not sure if this is true for pygame or not...  I'll check.

No. That would be bad. Then you'd lose all the benefits of being able to safely call Twisted stuff from your main thread.


I think you misunderstand the referenced URL. SDL events *are* thread safe, they're just not high performance in the face of threads and events will be dropped if the queue is full.

pygame's events are thread safe, but they inherit all the ugly from SDL and SDL_WaitEvent (including dropping upon full queue). Obviously the example I posted, which I wrote in 5 minutes, isn't full-proof.

I just committed an experimental fastevents wrapper, pygame.fastevent. Call pygame.fastevent.init() some time after pygame.init(), and then you can call pygame.fastevent.wait(), post(), etc.


-bob