aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/socketserver.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-04-09 00:49:17 +0200
committerAntoine Pitrou <solipsis@pitrou.net>2012-04-09 00:49:17 +0200
commitc9e8e3c4dd2cfb3506e9b4b3b87d27727fca4b5d (patch)
tree41a43f296c36043581b3743f388a2c6424790c05 /Lib/socketserver.py
parentf998810deb527b50adc9c40661a249ba58e163b8 (diff)
parentb0a9c66a49b6ced6748c33ecff407812facd723d (diff)
downloadcpython-c9e8e3c4dd2cfb3506e9b4b3b87d27727fca4b5d.tar.gz
cpython-c9e8e3c4dd2cfb3506e9b4b3b87d27727fca4b5d.zip
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/socketserver.py')
-rw-r--r--Lib/socketserver.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/Lib/socketserver.py b/Lib/socketserver.py
index a487e637612..261e28e6415 100644
--- a/Lib/socketserver.py
+++ b/Lib/socketserver.py
@@ -133,6 +133,7 @@ import socket
import select
import sys
import os
+import errno
try:
import threading
except ImportError:
@@ -147,6 +148,15 @@ if hasattr(socket, "AF_UNIX"):
"ThreadingUnixStreamServer",
"ThreadingUnixDatagramServer"])
+def _eintr_retry(func, *args):
+ """restart a system call interrupted by EINTR"""
+ while True:
+ try:
+ return func(*args)
+ except OSError as e:
+ if e.errno != errno.EINTR:
+ raise
+
class BaseServer:
"""Base class for server classes.
@@ -223,7 +233,8 @@ class BaseServer:
# connecting to the socket to wake this up instead of
# polling. Polling reduces our responsiveness to a
# shutdown request and wastes cpu at all other times.
- r, w, e = select.select([self], [], [], poll_interval)
+ r, w, e = _eintr_retry(select.select, [self], [], [],
+ poll_interval)
if self in r:
self._handle_request_noblock()
@@ -273,7 +284,7 @@ class BaseServer:
timeout = self.timeout
elif self.timeout is not None:
timeout = min(timeout, self.timeout)
- fd_sets = select.select([self], [], [], timeout)
+ fd_sets = _eintr_retry(select.select, [self], [], [], timeout)
if not fd_sets[0]:
self.handle_timeout()
return