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

Re: [pygame] 100% CPU FAQ



for event in []:
    print time.time()

event.get() will return an empty list if the event queue is empty.

With your code sample, this is happening many times per second thus using a lot of cpu.

Only when there is actually events in the event list will the for block be executed.

Stick the time.time() inside the while just before the event.get() and you will get a better idea of how often event.get is running.




On Thu, Jul 31, 2008 at 9:08 PM, techtonik <techtonik@xxxxxxxxx> wrote:
On Thu, Jul 31, 2008 at 11:31 AM, Noah Kantrowitz <noah@xxxxxxxxxxxxxx> wrote:

>>
>> The following example shows 100% load even with empty event queue when
>> pygame.event.get() is blocking.
>
> That would be because event.get() doesn't block. If you want to control your
> framerate (and therefore CPU usage) use pygame.time.Clock.
>

If it doesn't block when why print time is executed only when I pass
mouse over the window?

--
--anatoly t.