vmprof-python icon indicating copy to clipboard operation
vmprof-python copied to clipboard

time.sleep is broken with real_time=True

Open antocuni opened this issue 8 years ago • 0 comments

if you run this program, the time.sleep() ends immediately (CPython, Linux64, ubuntu):

import time
import vmprof

def main():
    f = open('xxx.vmprof', 'w+b')
    vmprof.enable(f.fileno(), real_time=True)
    time.sleep(3)
    vmprof.disable()

main()

According to strace, time.sleep() is implemented as a call to select; the normal behavior is this:

select(0, NULL, NULL, NULL, {3, 0})     = 0 (Timeout)

however, with real_time=True, I get this:

select(0, NULL, NULL, NULL, {3, 0})     = ? ERESTARTNOHAND (To be restarted if no handler)

I think that what happens is that the syscall is interrupted because the TIMER signal fired; CPython is not prepared to handle this case, and so it immediately exit the sleep(). However, I am not sure why it happens only in real_time mode.

antocuni avatar Oct 23 '17 09:10 antocuni