diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-04-09 00:47:24 +0200 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-04-09 00:47:24 +0200 |
commit | fa1d84107a22de80ee35a38e0c68ad988ebc66db (patch) | |
tree | 123903f9c68bd40f26a1cb08d896a770b7a61580 /Lib/test/test_socketserver.py | |
parent | 088a874c7ff4e90d5b6efc16d37a53a57f368fea (diff) | |
download | cpython-git-fa1d84107a22de80ee35a38e0c68ad988ebc66db.tar.gz |
Issue #7978: socketserver now restarts the select() call when EINTR is returned.
This avoids crashing the server loop when a signal is received.
Patch by Jerzy Kozera.
Diffstat (limited to 'Lib/test/test_socketserver.py')
-rw-r--r-- | Lib/test/test_socketserver.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py index 08fb03350d..07b0c193ea 100644 --- a/Lib/test/test_socketserver.py +++ b/Lib/test/test_socketserver.py @@ -8,6 +8,8 @@ import os import select import signal import socket +import select +import errno import tempfile import unittest import SocketServer @@ -225,6 +227,38 @@ class SocketServerTest(unittest.TestCase): SocketServer.DatagramRequestHandler, self.dgram_examine) + @contextlib.contextmanager + def mocked_select_module(self): + """Mocks the select.select() call to raise EINTR for first call""" + old_select = select.select + + class MockSelect: + def __init__(self): + self.called = 0 + + def __call__(self, *args): + self.called += 1 + if self.called == 1: + # raise the exception on first call + raise OSError(errno.EINTR, os.strerror(errno.EINTR)) + else: + # Return real select value for consecutive calls + return old_select(*args) + + select.select = MockSelect() + try: + yield select.select + finally: + select.select = old_select + + def test_InterruptServerSelectCall(self): + with self.mocked_select_module() as mock_select: + pid = self.run_server(SocketServer.TCPServer, + SocketServer.StreamRequestHandler, + self.stream_examine) + # Make sure select was called again: + self.assertGreater(mock_select.called, 1) + # Alas, on Linux (at least) recvfrom() doesn't return a meaningful # client address so this cannot work: |