@@ -133,6 +133,7 @@ class will essentially render the service "deaf" while one request is
133133import select
134134import sys
135135import os
136+ import errno
136137try :
137138 import threading
138139except ImportError :
@@ -147,6 +148,15 @@ class will essentially render the service "deaf" while one request is
147148 "ThreadingUnixStreamServer" ,
148149 "ThreadingUnixDatagramServer" ])
149150
151+ def _eintr_retry (func , * args ):
152+ """restart a system call interrupted by EINTR"""
153+ while True :
154+ try :
155+ return func (* args )
156+ except OSError as e :
157+ if e .errno != errno .EINTR :
158+ raise
159+
150160class BaseServer :
151161
152162 """Base class for server classes.
@@ -222,7 +232,8 @@ def serve_forever(self, poll_interval=0.5):
222232 # connecting to the socket to wake this up instead of
223233 # polling. Polling reduces our responsiveness to a
224234 # shutdown request and wastes cpu at all other times.
225- r , w , e = select .select ([self ], [], [], poll_interval )
235+ r , w , e = _eintr_retry (select .select , [self ], [], [],
236+ poll_interval )
226237 if self in r :
227238 self ._handle_request_noblock ()
228239 finally :
@@ -262,7 +273,7 @@ def handle_request(self):
262273 timeout = self .timeout
263274 elif self .timeout is not None :
264275 timeout = min (timeout , self .timeout )
265- fd_sets = select .select ( [self ], [], [], timeout )
276+ fd_sets = _eintr_retry ( select .select , [self ], [], [], timeout )
266277 if not fd_sets [0 ]:
267278 self .handle_timeout ()
268279 return
0 commit comments