diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2013-08-17 18:27:56 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2013-08-17 18:27:56 (GMT) |
commit | 6f6ec37838b424c5d5ccef9a640ad02b7d1cb92f (patch) | |
tree | ea727add92c9765d5e33d37a563a3d0deba30e4e /Lib/test/test_signal.py | |
parent | f920a1c1f132adb10fe81ea430f08c7b61d5cc9d (diff) | |
download | cpython-6f6ec37838b424c5d5ccef9a640ad02b7d1cb92f.zip cpython-6f6ec37838b424c5d5ccef9a640ad02b7d1cb92f.tar.gz cpython-6f6ec37838b424c5d5ccef9a640ad02b7d1cb92f.tar.bz2 |
Issue #16105: When a signal handler fails to write to the file descriptor registered with ``signal.set_wakeup_fd()``, report an exception instead of ignoring the error.
Diffstat (limited to 'Lib/test/test_signal.py')
-rw-r--r-- | Lib/test/test_signal.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py index 1efb5f7..0564740 100644 --- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -275,6 +275,47 @@ class WakeupSignalTests(unittest.TestCase): assert_python_ok('-c', code) + def test_wakeup_write_error(self): + # Issue #16105: write() errors in the C signal handler should not + # pass silently. + # Use a subprocess to have only one thread. + code = """if 1: + import errno + import fcntl + import os + import signal + import sys + import time + from test.support import captured_stderr + + def handler(signum, frame): + 1/0 + + signal.signal(signal.SIGALRM, handler) + r, w = os.pipe() + flags = fcntl.fcntl(r, fcntl.F_GETFL, 0) + fcntl.fcntl(r, fcntl.F_SETFL, flags | os.O_NONBLOCK) + + # Set wakeup_fd a read-only file descriptor to trigger the error + signal.set_wakeup_fd(r) + try: + with captured_stderr() as err: + signal.alarm(1) + time.sleep(5.0) + except ZeroDivisionError: + # An ignored exception should have been printed out on stderr + err = err.getvalue() + if ('Exception ignored when trying to write to the signal wakeup fd' + not in err): + raise AssertionError(err) + if ('OSError: [Errno %d]' % errno.EBADF) not in err: + raise AssertionError(err) + else: + raise AssertionError("ZeroDivisionError not raised") + """ + + assert_python_ok('-c', code) + def test_wakeup_fd_early(self): self.check_wakeup("""def test(): import select |