diff -r 57e3c4ae37ea Lib/test/test_socket.py --- a/Lib/test/test_socket.py Sat Jul 26 13:44:50 2014 +0100 +++ b/Lib/test/test_socket.py Thu Jul 31 20:37:46 2014 +0100 @@ -693,23 +693,22 @@ self.assertRaises(ValueError, math.acosh, 0) 1 // 0 c, s = socket.socketpair() - old_alarm = signal.signal(signal.SIGALRM, raising_handler) - try: - if with_timeout: - # Just above the one second minimum for signal.alarm - c.settimeout(1.5) - with self.assertRaises(ZeroDivisionError): - signal.alarm(1) - c.sendall(b"x" * test_support.SOCK_MAX_SIZE) - if with_timeout: - signal.signal(signal.SIGALRM, ok_handler) - signal.alarm(1) - self.assertRaises(socket.timeout, c.sendall, - b"x" * test_support.SOCK_MAX_SIZE) - finally: - signal.signal(signal.SIGALRM, old_alarm) - c.close() - s.close() + self.addCleanup(c.close) + self.addCleanup(s.close) + orig_alrm_handler = signal.signal(signal.SIGALRM, raising_handler) + self.addCleanup(signal.signal, signal.SIGALRM, orig_alrm_handler) + self.addCleanup(signal.alarm, 0) + if with_timeout: + # Just above the one second minimum for signal.alarm + c.settimeout(1.5) + with self.assertRaises(ZeroDivisionError): + signal.alarm(1) + c.sendall(b"x" * test_support.SOCK_MAX_SIZE) + if with_timeout: + signal.signal(signal.SIGALRM, ok_handler) + signal.alarm(1) + self.assertRaises(socket.timeout, c.sendall, + b"x" * test_support.SOCK_MAX_SIZE) def test_sendall_interrupted(self): self.check_sendall_interrupted(False)