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

[pygame] Re: Is pygame event thread save? or I need use lock to post user event in thread?



thank you all,
and I will try it.

On Nov 25, 4:54 am, "René Dudfield" <ren...@xxxxxxxxx> wrote:
> hi,
>
> Posting an event is *not* really thread-good.  It will work, but will
> start raising exceptions if you do it from multiple threads.  You can
> make a post function that retries on exceptions, but then you may get
> worse performance.
>
> Use the fastevent module instead if you want to use threads.  The only
> main difference is that you can't peek at the event queue... which no
> one really does any way.  It is designed to be much faster with
> threads, and is thread-good :)
>
> Using the fastevent module is much nicer, and I hope we will finally
> make it into pygame 1.9 as the default event module.
>
> I've done a number of programs using threads, and the fastevent module
> is the way to go.
>
> cu!
>
> On Tue, Nov 25, 2008 at 2:33 AM, Peter Shinners <p...@xxxxxxxxxxxx> wrote:
> > halida wrote:
>
> >> I want to use multi-thread in pygame game loop,
> >> with main draw and display.update thread,
> >>  event process thread,
> >> game update thread.
> >> and I will use event.post(drawEvent) to tell main thread  to update
> >> screen.
> >> do I need use threading.Lock()  to lock it? or just let it go?
> >> it is too hard to read pygame source code for me.
>
> > Posting an event is thread safe, you will not need to worry about locking.
>
> > I'm pretty sure you must still get events from the main thread. Getting
> > events is very tied to the platform.