diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2006-08-02 06:46:21 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2006-08-02 06:46:21 (GMT) |
commit | 9b0ca79213f262daab54db21d6f3aa17b8dd86dd (patch) | |
tree | 07e79ed0e6c833b954f0e89b0b114b2c7fa5a432 /Lib/test | |
parent | 3ee5941f68fea95116e30a78fb0cc2fb359c48ea (diff) | |
download | cpython-9b0ca79213f262daab54db21d6f3aa17b8dd86dd.zip cpython-9b0ca79213f262daab54db21d6f3aa17b8dd86dd.tar.gz cpython-9b0ca79213f262daab54db21d6f3aa17b8dd86dd.tar.bz2 |
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
a socket operation on a socket with a timeout, the exception will be
caught correctly. Previously, the exception was not caught.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_socket.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index b7d3916..356b801 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -11,6 +11,7 @@ import Queue import sys import array from weakref import proxy +import signal PORT = 50007 HOST = 'localhost' @@ -817,6 +818,37 @@ class TCPTimeoutTest(SocketTCPTest): if not ok: self.fail("accept() returned success when we did not expect it") + def testInterruptedTimeout(self): + # XXX I don't know how to do this test on MSWindows or any other + # plaform that doesn't support signal.alarm() or os.kill(), though + # the bug should have existed on all platforms. + if not hasattr(signal, "alarm"): + return # can only test on *nix + self.serv.settimeout(5.0) # must be longer than alarm + class Alarm(Exception): + pass + def alarm_handler(signal, frame): + raise Alarm + old_alarm = signal.signal(signal.SIGALRM, alarm_handler) + try: + signal.alarm(2) # POSIX allows alarm to be up to 1 second early + try: + foo = self.serv.accept() + except socket.timeout: + self.fail("caught timeout instead of Alarm") + except Alarm: + pass + except: + self.fail("caught other exception instead of Alarm") + else: + self.fail("nothing caught") + signal.alarm(0) # shut off alarm + except Alarm: + self.fail("got Alarm in wrong place") + finally: + # no alarm can be pending. Safe to restore old handler. + signal.signal(signal.SIGALRM, old_alarm) + class UDPTimeoutTest(SocketTCPTest): def testUDPTimeout(self): |