0
101 May 12, 2008 at 12:24

I’m trying to make a periodic timer and i’ve ran into a problem, i get thhis error,

“signal.signal(signal.SIGALRM, alarm_handler)
AttributeError: ‘module’ object has no attribute ‘SIGALRM’”

anyone know how whats wrong?

import signal, time
interval = 1.0
ticks = 0
def alarm_handler(signo,frame):
global ticks
print "Alarm ", ticks
ticks = ticks + 1
signal.alarm(interval)                # Schedule a new alarm

signal.signal(signal.SIGALRM, alarm_handler)
signal.alarm(interval)
# Spin forever--should see handler being called every second
while 1:
pass


#### 10 Replies

0
102 May 13, 2008 at 17:08

Windows doesn’t support SIGALRM. Try it on a real POSIX system and it will work. I tested it on Linux and it’s fine.

0
101 May 13, 2008 at 18:53

@monjardin

Windows doesn’t support SIGALRM. Try it on a real POSIX system and it will work. I tested it on Linux and it’s fine.

well what do i use for windows?

0
102 May 13, 2008 at 20:44

That depends on what you’re doing with it, but you could get the same functionality with the first result of a google search for “python timer”: http://docs.python.org/lib/timer-objects.html

0
101 May 13, 2008 at 22:04

monjardin: I see that JwN meter going up ;)

0
101 May 14, 2008 at 08:52

Did it ever go down?

0
102 May 15, 2008 at 16:53

It’s been in the red for a few years. So, I guess it’s about time I update it to a level more reflective of current my “jadedness”.

0
101 May 17, 2008 at 02:54

Ok back on topic, i need a delay timer or something like that so i can set the turn rate of the players sprite. right now i’m using pygame.time.wait(20), this slows down the game and ya that sucks. So how can i have it so it turns at a given (and can be changed) interval?

0
167 May 17, 2008 at 03:24

Well, the way most games do that is they actually measure how long it takes to do one frame (rendering, logic, everything), and scale all rates of change by that value. For instance, you’d express your turn rate in degrees per second, and each frame you would calculate the amount to turn by multiplying that by the frame time in seconds.

To measure the frame time, you can just stick something in your main game loop that calls pygame.time.get_ticks each frame and calculates the difference from the previous frame’s ticks value. This is the number of milliseconds the last frame took, which is normally a pretty good estimate of the number of milliseconds the current frame will take.

0
101 May 17, 2008 at 23:33

ok, i have no idea how to even start to code that. can you show some code?

0
101 May 21, 2008 at 19:56

@ccoff

i[](http://www.funingame.com)like [](http://www.funingame.com/eve.html)your[](http://www.funingame.com/guildwars.html)article[](http://www.funingame.com/maplestory.html)very[](http://www.allgamegold.com)much。

Huh?