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

Re: [pygame] Weird problem



Kai Kuehne wrote:
Currently I'm wondering why this program produces nearly 100%
cpu load:

while 1:
   for event in pygame.event.get():

This caught me out, too. The event.get() function does *not* block waiting for an event to arrive -- if there are no events in the queue when it's called, it returns an empty list.

Try using event.wait() instead, which blocks
until an event arrives. It only returns one
event, but that doesn't usually matter, because
your loop will get the next one the next time
around.

If you really need to handle multiple events
on each loop, use event.wait() to get the first
one and then event.get() to get the remaining
ones.

--
Greg