Skip to content

time.sleep(n) interrupted by signal #76238

Closed

Description

@BogdanPopa
BPO 32057
Nosy @vstinner

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 2017-11-17.10:56:37.713>
created_at = <Date 2017-11-17.10:17:39.990>
labels = ['interpreter-core']
title = 'time.sleep(n) interrupted by signal'
updated_at = <Date 2017-11-17.10:56:37.711>
user = 'https://bugs.python.org/BogdanPopa'

bugs.python.org fields:

activity = <Date 2017-11-17.10:56:37.711>
actor = 'Bogdan Popa'
assignee = 'none'
closed = True
closed_date = <Date 2017-11-17.10:56:37.713>
closer = 'Bogdan Popa'
components = ['Interpreter Core']
creation = <Date 2017-11-17.10:17:39.990>
creator = 'Bogdan Popa'
dependencies = []
files = []
hgrepos = []
issue_num = 32057
keywords = []
message_count = 4.0
messages = ['306427', '306428', '306429', '306430']
nosy_count = 2.0
nosy_names = ['vstinner', 'Bogdan Popa']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue32057'
versions = ['Python 3.4']

Activity

  1. BogdanPopa commented on Nov 17, 2017

    BogdanPopamannequin
    MannequinAuthor

    I ran into this while backporting some code from 3.6 to 3.5 and 3.4. The following piece of code prints one line every second, as expected, on 3.6 and 3.5, but it doesn't on 3.4. It looks like the signal is able to wake up the main thread from sleeping:

    import time
    import signal
    
    
    def handle(signum, mask):
        print("received signal at", time.time())
    
    
    signal.setitimer(signal.ITIMER_REAL, 1, 1)
    signal.signal(signal.SIGALRM, handle)
    
    for _ in range(2):
        now = time.time()
        delta = 1 - (time.time() - int(time.time()))
        time.sleep(delta)
        print(now, delta, time.time())
    

    If I remove the timer, then everything works as expected on 3.4.

    Here is some sample output from 3.6:

    1510913832.4726589 0.5273411273956299 1510913833.000339
    received signal at 1510913833.477888
    1510913833.000449 0.9995510578155518 1510913834.000187
    

    And some from 3.4:

    1510913813.525479 0.4745209217071533 1510913814.004106
    received signal at 1510913814.529313
    1510913814.004233 0.9957659244537354 1510913814.529413
    
  2. added
    interpreter-core
    on Nov 17, 2017
  3. BogdanPopa commented on Nov 17, 2017

    BogdanPopamannequin
    MannequinAuthor

    I forgot to mention that I am on macOS Sierra (10.12.6) and I ran the code on Python 3.4.6, 3.5.3 and 3.6.3, respectively.

  4. vstinner commented on Nov 17, 2017

    @vstinner
    Member

    I'm sorry but Python 3.4 doesn't accept bugfixes anymore. Same for Python 3.5.
    https://devguide.python.org/#status-of-python-branches

    The following piece of code prints one line every second, as expected, on 3.6 and 3.5

    Good, at least Python behaves as you want :-) Maybe it's an enhancement caused by the PEP-475.

  5. BogdanPopa commented on Nov 17, 2017

    BogdanPopamannequin
    MannequinAuthor

    Fair enough. From reading PEP-475, it does look like that's what fixed it. Thanks Victor!

  6. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions