Skip to content

Commit d7df812

Browse files
Added timeout loop
1 parent 83014b5 commit d7df812

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

Lib/multiprocessing/connection.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ class Listener(object):
470470
connections, or for a Windows named pipe.
471471
'''
472472
def __init__(self, address=None, family=None, backlog=1, authkey=None):
473+
473474
family = family or (address and address_type(address)) \
474475
or default_family
475476
address = address or arbitrary_address(family)
@@ -485,6 +486,10 @@ def __init__(self, address=None, family=None, backlog=1, authkey=None):
485486

486487
self._authkey = authkey
487488

489+
def settimeout(self, timeout):
490+
if timeout:
491+
self._listener.settimeout(timeout)
492+
488493
def accept(self):
489494
'''
490495
Accept a connection on the bound socket or named pipe of `self`.
@@ -639,6 +644,9 @@ def __init__(self, address, family, backlog=1):
639644
else:
640645
self._unlink = None
641646

647+
def settimeout(self, timeout):
648+
self._socket.settimeout(timeout)
649+
642650
def accept(self):
643651
s, self._last_accepted = self._socket.accept()
644652
s.setblocking(True)
@@ -697,6 +705,9 @@ def _new_handle(self, first=False):
697705
_winapi.NMPWAIT_WAIT_FOREVER, _winapi.NULL
698706
)
699707

708+
def settimeout(self, timeout):
709+
pass
710+
700711
def accept(self):
701712
self._handle_queue.append(self._new_handle())
702713
handle = self._handle_queue.pop(0)

Lib/multiprocessing/managers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,15 @@ def serve_forever(self):
191191
def accepter(self):
192192
while True:
193193
try:
194+
self.listener.settimeout(20)
194195
c = self.listener.accept()
195196
except OSError:
196197
continue
197198
t = threading.Thread(target=self.handle_request, args=(c,))
198199
t.daemon = True
199200
t.start()
201+
if self.stop_event.is_set():
202+
break
200203

201204
def _handle_request(self, c):
202205
request = None

0 commit comments

Comments
 (0)