Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4def515

Browse files
committed
Merged revisions 76247 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ................ r76247 | antoine.pitrou | 2009-11-13 23:35:18 +0100 (ven., 13 nov. 2009) | 12 lines Merged revisions 76245 via svnmerge from svn+ssh://[email protected]/python/trunk ........ r76245 | antoine.pitrou | 2009-11-13 23:31:18 +0100 (ven., 13 nov. 2009) | 6 lines Issue #7318: multiprocessing now uses a timeout when it fails to establish a connection with another process, rather than looping endlessly. The default timeout is 20 seconds, which should be amply sufficient for local connections. ........ ................
1 parent ca15409 commit 4def515

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

Lib/multiprocessing/connection.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#
2828

2929
BUFSIZE = 8192
30+
# A very generous timeout when it comes to local connections...
31+
CONNECTION_TIMEOUT = 20.
3032

3133
_mmap_counter = itertools.count()
3234

@@ -41,6 +43,13 @@
4143
default_family = 'AF_PIPE'
4244
families += ['AF_PIPE']
4345

46+
47+
def _init_timeout(timeout=CONNECTION_TIMEOUT):
48+
return time.time() + timeout
49+
50+
def _check_timeout(t):
51+
return time.time() > t
52+
4453
#
4554
#
4655
#
@@ -247,12 +256,13 @@ def SocketClient(address):
247256
'''
248257
family = address_type(address)
249258
s = socket.socket( getattr(socket, family) )
259+
t = _init_timeout()
250260

251261
while 1:
252262
try:
253263
s.connect(address)
254264
except socket.error as e:
255-
if e.args[0] != errno.ECONNREFUSED: # connection refused
265+
if e.args[0] != errno.ECONNREFUSED or _check_timeout(t):
256266
debug('failed to connect to address %s', address)
257267
raise
258268
time.sleep(0.01)
@@ -322,6 +332,7 @@ def PipeClient(address):
322332
'''
323333
Return a connection object connected to the pipe given by `address`
324334
'''
335+
t = _init_timeout()
325336
while 1:
326337
try:
327338
win32.WaitNamedPipe(address, 1000)
@@ -331,7 +342,7 @@ def PipeClient(address):
331342
)
332343
except WindowsError as e:
333344
if e.args[0] not in (win32.ERROR_SEM_TIMEOUT,
334-
win32.ERROR_PIPE_BUSY):
345+
win32.ERROR_PIPE_BUSY) or _check_timeout(t):
335346
raise
336347
else:
337348
break

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ Core and Builtins
4040
Library
4141
-------
4242

43+
- Issue #7318: multiprocessing now uses a timeout when it fails to establish
44+
a connection with another process, rather than looping endlessly. The
45+
default timeout is 20 seconds, which should be amply sufficient for
46+
local connections.
47+
4348
- Issue #7282: Fix a memory leak when an RLock was used in a thread other
4449
than those started through `threading.Thread` (for example, using
4550
`_thread.start_new_thread()`).

0 commit comments

Comments
 (0)