Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time.sleep(1): call PyErr_CheckSignals() if the sleep was interrupted #56671

Closed
vstinner opened this issue Jul 1, 2011 · 5 comments
Closed
Labels
stdlib Python modules in the Lib dir

Comments

@vstinner
Copy link
Member

vstinner commented Jul 1, 2011

BPO 12462
Nosy @pitrou, @vstinner
Files
  • sleep_signal.patch
  • sleep_signal-2.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2011-07-01.12:20:34.299>
    created_at = <Date 2011-07-01.10:25:05.799>
    labels = ['library']
    title = 'time.sleep(1): call PyErr_CheckSignals() if the sleep was interrupted'
    updated_at = <Date 2011-07-01.12:20:34.298>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2011-07-01.12:20:34.298>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-07-01.12:20:34.299>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2011-07-01.10:25:05.799>
    creator = 'vstinner'
    dependencies = []
    files = ['22534', '22536']
    hgrepos = []
    issue_num = 12462
    keywords = ['patch']
    message_count = 5.0
    messages = ['139562', '139564', '139567', '139568', '139570']
    nosy_count = 3.0
    nosy_names = ['pitrou', 'vstinner', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue12462'
    versions = ['Python 3.3']

    @vstinner
    Copy link
    Member Author

    vstinner commented Jul 1, 2011

    While reading floatsleep() (time.sleep) code for issue bpo-12459, I noticed that the Python signal handler is not called in floatsleep() if a signal interrupted the sleep. Well, it just "works" because the bytecode evaluation loop will call PyErr_CheckSignals() before executing the next instruction (the C signal handler signals calls Py_AddPendingCall whichs signals that the pending call to the eval loop using "eval_breaker"), but it would be better to call it directly.

    Attached calls explicitly and immediatly PyErr_CheckSignals() in the sleep and Windows implementations of floatsleep().

    It's not really a bug, so I prefer to not touch Python 2.7 and 3.2, only Python 3.3.

    @vstinner vstinner added the stdlib Python modules in the Lib dir label Jul 1, 2011
    @pitrou
    Copy link
    Member

    pitrou commented Jul 1, 2011

    You don't *need* to call PyErr_CheckSignals() explicitly, PyErr_SetFromErrno() does it for you.

    @vstinner
    Copy link
    Member Author

    vstinner commented Jul 1, 2011

    The sleep implementation of floatsleep() doesn't call PyErr_SetFromErrno() if errno is EINTR, whereas EINTR indicates that select() was interrupted. I agree that PyErr_CheckSignals() is overkill in the Windows implementation.

    My new patch is more explicit: only add a special case for the select implementation, if errno is EINTR.

    @pitrou
    Copy link
    Member

    pitrou commented Jul 1, 2011

    My new patch is more explicit: only add a special case for the select
    implementation, if errno is EINTR.

    Looks good to me!

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jul 1, 2011

    New changeset 583be15e22ca by Victor Stinner in branch 'default':
    Issue bpo-12462: time.sleep() now calls immediatly the (Python) signal handler if
    http://hg.python.org/cpython/rev/583be15e22ca

    @vstinner vstinner closed this as completed Jul 1, 2011
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    webknjaz added a commit to webknjaz/cheroot that referenced this issue Mar 21, 2024
    `IOError` is an alias of `OSError` since Python 3.3. Python 3 also
    indroduced a new exception `InterruptedError` which represents
    `EINTR`. The `time.sleep()` call could raise
    
        IOError: [Errno 4] Interrupted function call
    
    on KBInt under Python 2, which would be `InterruptedError` under
    Python 3 but it's not raised anymore post PEP 475 that was implemented
    in Python 3.5. So it does not actually need to be handled in modern
    runtimes.
    
    Refs:
    * https://stackoverflow.com/a/52613818/595220
    * https://peps.python.org/pep-0475/
    * python/cpython#56671
    * https://stackoverflow.com/a/38258781/595220
    * https://docs.python.org/3/library/exceptions.html#InterruptedError
    * python/cpython#36893
    webknjaz added a commit to webknjaz/cheroot that referenced this issue Mar 23, 2024
    `IOError` is an alias of `OSError` since Python 3.3. Python 3 also
    indroduced a new exception `InterruptedError` which represents
    `EINTR`. The `time.sleep()` call could raise
    
        IOError: [Errno 4] Interrupted function call
    
    on KBInt under Python 2, which would be `InterruptedError` under
    Python 3 but it's not raised anymore post PEP 475 that was implemented
    in Python 3.5. So it does not actually need to be handled in modern
    runtimes.
    
    Refs:
    * https://stackoverflow.com/a/52613818/595220
    * https://peps.python.org/pep-0475/
    * python/cpython#56671
    * https://stackoverflow.com/a/38258781/595220
    * https://docs.python.org/3/library/exceptions.html#InterruptedError
    * python/cpython#36893
    webknjaz added a commit to webknjaz/cheroot that referenced this issue Mar 23, 2024
    `IOError` is an alias of `OSError` since Python 3.3. Python 3 also
    indroduced a new exception `InterruptedError` which represents
    `EINTR`. The `time.sleep()` call could raise
    
        IOError: [Errno 4] Interrupted function call
    
    on KBInt under Python 2, which would be `InterruptedError` under
    Python 3 but it's not raised anymore post PEP 475 that was implemented
    in Python 3.5. So it does not actually need to be handled in modern
    runtimes.
    
    Refs:
    * https://stackoverflow.com/a/52613818/595220
    * https://peps.python.org/pep-0475/
    * python/cpython#56671
    * https://stackoverflow.com/a/38258781/595220
    * https://docs.python.org/3/library/exceptions.html#InterruptedError
    * python/cpython#36893
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants