Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python timer mystery

Tags:

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?