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

Re: [pygame] Weird problem



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

while 1:
   for event in pygame.event.get():
       if event.type == KEYDOWN or event.type == QUIT:
           if event.key == K_ESCAPE:
               import sys
               sys.exit()

I tested my whole game and didn't think it would be this simple
code sample that produces this load. I'm not using clock here
since i thought *clock* would be the problem.

Have you an idea what the reason could be? I mean.. I just do
nothing other than looping and waiting for a key input. Why
is there such an high cpu-load? Is this 'normal'?
pygame.time.wait

     pause the program for an amount of time
     pygame.time.wait(milliseconds): return time

Will pause for a given number of milliseconds. This function sleeps the process to share the processor with other programs. A program that waits for even a few milliseconds will consume very little processor time. It is slightly less accurate than the pygame.time.delay - pause the program for an amount of time function.

This returns the actual number of milliseconds used.


pygame.time.delay

     pause the program for an amount of time
     pygame.time.delay(milliseconds): return time

Will pause for a given number of milliseconds. This function will use the processor (rather than sleeping) in order to make the delay more accurate than pygame.time.wait - pause the program for an amount of time.

     This returns the actual number of milliseconds used.


HTH, -Luke