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

SIGALRM fails to interrupt time.sleep() call on Python 3.5 #72652

Closed
ryanpetrello mannequin opened this issue Oct 18, 2016 · 2 comments
Closed

SIGALRM fails to interrupt time.sleep() call on Python 3.5 #72652

ryanpetrello mannequin opened this issue Oct 18, 2016 · 2 comments
Labels
stdlib Python modules in the Lib dir

Comments

@ryanpetrello
Copy link
Mannequin

ryanpetrello mannequin commented Oct 18, 2016

BPO 28466
Nosy @vadmium

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 2016-10-18.03:16:43.800>
created_at = <Date 2016-10-18.02:52:22.720>
labels = ['invalid', 'library']
title = 'SIGALRM fails to interrupt time.sleep() call on Python 3.5'
updated_at = <Date 2016-10-18.03:16:43.791>
user = 'https://bugs.python.org/ryanpetrello'

bugs.python.org fields:

activity = <Date 2016-10-18.03:16:43.791>
actor = 'martin.panter'
assignee = 'none'
closed = True
closed_date = <Date 2016-10-18.03:16:43.800>
closer = 'martin.panter'
components = ['Library (Lib)']
creation = <Date 2016-10-18.02:52:22.720>
creator = 'ryan.petrello'
dependencies = []
files = []
hgrepos = []
issue_num = 28466
keywords = []
message_count = 2.0
messages = ['278835', '278838']
nosy_count = 2.0
nosy_names = ['martin.panter', 'ryan.petrello']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue28466'
versions = ['Python 3.5']

@ryanpetrello
Copy link
Mannequin Author

ryanpetrello mannequin commented Oct 18, 2016

I may have found a bug in SIGALRM handling in Python3.5. I've not been able to reproduce the same issue in Python2.7 or 3.4. Here's a simple example that illustrates the issue (which I'm able to reproduce on OS X 10.11.3 El Capitan and Ubuntu 14.04):

$ python2 --version; python3.4 --version; python3.5 --version
Python 2.7.11
Python 3.4.4
Python 3.5.1

$ cat alarm.py
import signal, time
def handler(signum, frame):
    print('Signal handler called with signal %s' % signum)

# Set the signal handler and a 1-second alarm
signal.signal(signal.SIGALRM, handler)
signal.alarm(1)

# We should not actually sleep for 10 seconds
time.sleep(10)
signal.alarm(0)
$ time python2 alarm.py
Signal handler called with signal 14
python2 alarm.py  0.04s user 0.02s system 5% cpu 1.075 total

$ time python3.4 alarm.py
Signal handler called with signal 14
python3.4 alarm.py  0.07s user 0.01s system 7% cpu 1.092 total

$ time python3.5 alarm.py
Signal handler called with signal 14
python3.5 alarm.py  0.09s user 0.02s system 1% cpu 10.115 total

Note that when run under python3.5, the program does not exit until 10 seconds have passed.

@ryanpetrello ryanpetrello mannequin added the stdlib Python modules in the Lib dir label Oct 18, 2016
@ryanpetrello ryanpetrello mannequin changed the title SIGALRM fails to interrupt time.sleep() call on Python 3.6 SIGALRM fails to interrupt time.sleep() call on Python 3.5 Oct 18, 2016
@vadmium
Copy link
Member

vadmium commented Oct 18, 2016

This is by design; see PEP-475, and the documentation <https://docs.python.org/3.5/library/time.html#time.sleep\>.

If you make your signal handler raise an exception, it will interrupt the sleep() call most of the time. But if the signal happens to be received just before the sleep() call is about to be entered, the handler will only be run when the underlying OS sleep() call returns 10 s later.

@vadmium vadmium closed this as completed Oct 18, 2016
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
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

1 participant