python timer mystery

大憨熊 提交于 2019-12-01 16:58:42

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.

The signal.ITIMER_VIRTUAL only counts down with the process is running. time.sleep(5) suspends the process so the timer doesn't decrement.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!