python timer mystery

前端 未结 2 1990
深忆病人
深忆病人 2021-01-18 00:33

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

import time
import signal

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

signal.signal(signal.SIGALRM         


        
2条回答
  •  心在旅途
    2021-01-18 01:23

    From my system's man setitimer (emphasis mine):

    The system provides each process with three interval timers, each decrementing in a distinct time domain. When any timer expires, a signal is sent to the process, and the timer (potentially) restarts.

    ITIMER_REAL decrements in real time, and delivers SIGALRM upon expiration.

    ITIMER_VIRTUAL decrements only when the process is executing, and delivers SIGVTALRM upon expiration.

    Did you just miss that your process isn't executing while sleeping? It's going to take an awfully long time for you to accrue actually-used time with that loop.

提交回复
热议问题