Skip to content

time.sleep is broken with real_time=True #159

@antocuni

Description

@antocuni

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions