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

[pygame] strange behavior with pygame.time module



I sent a different email related to this problem a little while ago, but
I was not subscribed to the list, and I was also having issues with my
email setup -- so one or the other kept my message from making it to the
list.  Anyway, hopefully this one makes it.

I'm having strange behavior with what seems like most of the time
module.  Using pygame.time.wait as a per-frame delay in my main loop
pegs the CPU, which the docs say it shouldn't.  If I use the exact same
code except change pygame.time.wait(time_in_ms) to
time.sleep(time_in_secs), then my CPU usage is reasonable (20% or
whatever, at 100fps).

Since time.Clock uses pygame.time.wait, I coded my own little version of
it.  I use it the exact same interface/behavior as time.Clock, except
that I sleep with time.sleep.  Again, if I swap this out for
pygame.time.wait, my CPU gets stuck at full usage.

I also tried doing a 5-second sleep with time.sleep, pygame.time.wait,
and pygame.time.delay, just out of curiosity.  None of them used up any
CPU during this, which I thought was somewhat strange.

So basically I've had to go about reimplementing much of the pygame.time
module, built around plain python time.sleep.  It works great.  But why
doesn't pygame's time stuff work right for me?

I'm running ubuntu breezy, on a tualatin celeron 1.2ghz, 384mb ram, with
a 32mb ati radeon.

Any ideas?

Oh, and just so you know it's not some whacky code in my game causing
problems, this minimal test script pegs my CPU too:

        import pygame
        pygame.init()
        t = pygame.time.Clock()
        while 1:
            t.tick(100)

But this does not:

        import time
        while 1:
            time.sleep(0.01)

And in yet another twist, neither does this:

        import pygame
        pygame.init()
        while 1:
            pygame.time.wait(10)

Confused,
-- 
Nick Welch | mack @ incise.org | http://incise.org