# python periodic timer

10 replies to this topic

### #1Arg0

New Member

• Members
• 20 posts

Posted 12 May 2008 - 12:24 PM

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



### #2monjardin

Senior Member

• Members
• 1033 posts

Posted 13 May 2008 - 05:08 PM

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.
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*

### #3Arg0

New Member

• Members
• 20 posts

Posted 13 May 2008 - 06:53 PM

monjardin said:

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?

### #4monjardin

Senior Member

• Members
• 1033 posts

Posted 13 May 2008 - 08:44 PM

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.o...er-objects.html
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*

### #5anubis

Senior Member

• Members
• 2225 posts

Posted 13 May 2008 - 10:04 PM

monjardin: I see that JwN meter going up ;)
If Prolog is the answer, what is the question ?

### #6Kenneth Gorking

Senior Member

• Members
• 939 posts

Posted 14 May 2008 - 08:52 AM

Did it ever go down?
"Stupid bug! You go squish now!!" - Homer Simpson

### #7monjardin

Senior Member

• Members
• 1033 posts

Posted 15 May 2008 - 04:53 PM

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".
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*

### #8Arg0

New Member

• Members
• 20 posts

Posted 17 May 2008 - 02:54 AM

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?

### #9Reedbeta

DevMaster Staff

• 5305 posts
• LocationBellevue, WA

Posted 17 May 2008 - 03:24 AM

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.
reedbeta.com - developer blog, OpenGL demos, and other projects

### #10Arg0

New Member

• Members
• 20 posts

Posted 17 May 2008 - 11:33 PM

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

### #11Arg0

New Member

• Members
• 20 posts

Posted 21 May 2008 - 07:56 PM

ccoff said:

i like your article very much。

Huh?

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users