Thursday, February 18, 2010

Programmer - python timer mystery

Programmer Question

Well, at least a mystery to me. Consider the following:



import time
import signal

def catcher(signum, _):
print "beat!"

signal.signal(signal.SIGALRM, catcher)
signal.setitimer(signal.ITIMER_REAL, 2, 2)

while True:
time.sleep(5)


Works as expected i.e. delivers a "beat!" message every 2 seconds. Next, no output is produced:



import time
import signal

def catcher(signum, _):
print "beat!"

signal.signal(signal.SIGVTALRM, catcher)
signal.setitimer(signal.ITIMER_VIRTUAL, 2, 2)

while True:
time.sleep(5)


Where is the issue?

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails