mirror of https://github.com/python/cpython
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.
This commit is contained in:
parent
c4a346cc55
commit
c562ca4625
|
@ -27,6 +27,8 @@ from multiprocessing.forking import duplicate, close
|
||||||
#
|
#
|
||||||
|
|
||||||
BUFSIZE = 8192
|
BUFSIZE = 8192
|
||||||
|
# A very generous timeout when it comes to local connections...
|
||||||
|
CONNECTION_TIMEOUT = 20.
|
||||||
|
|
||||||
_mmap_counter = itertools.count()
|
_mmap_counter = itertools.count()
|
||||||
|
|
||||||
|
@ -41,6 +43,13 @@ if sys.platform == 'win32':
|
||||||
default_family = 'AF_PIPE'
|
default_family = 'AF_PIPE'
|
||||||
families += ['AF_PIPE']
|
families += ['AF_PIPE']
|
||||||
|
|
||||||
|
|
||||||
|
def _init_timeout(timeout=CONNECTION_TIMEOUT):
|
||||||
|
return time.time() + timeout
|
||||||
|
|
||||||
|
def _check_timeout(t):
|
||||||
|
return time.time() > t
|
||||||
|
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
@ -247,12 +256,13 @@ def SocketClient(address):
|
||||||
'''
|
'''
|
||||||
family = address_type(address)
|
family = address_type(address)
|
||||||
s = socket.socket( getattr(socket, family) )
|
s = socket.socket( getattr(socket, family) )
|
||||||
|
t = _init_timeout()
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
s.connect(address)
|
s.connect(address)
|
||||||
except socket.error, e:
|
except socket.error, e:
|
||||||
if e.args[0] != errno.ECONNREFUSED: # connection refused
|
if e.args[0] != errno.ECONNREFUSED or _check_timeout(t):
|
||||||
debug('failed to connect to address %s', address)
|
debug('failed to connect to address %s', address)
|
||||||
raise
|
raise
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
@ -322,6 +332,7 @@ if sys.platform == 'win32':
|
||||||
'''
|
'''
|
||||||
Return a connection object connected to the pipe given by `address`
|
Return a connection object connected to the pipe given by `address`
|
||||||
'''
|
'''
|
||||||
|
t = _init_timeout()
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
win32.WaitNamedPipe(address, 1000)
|
win32.WaitNamedPipe(address, 1000)
|
||||||
|
@ -331,7 +342,7 @@ if sys.platform == 'win32':
|
||||||
)
|
)
|
||||||
except WindowsError, e:
|
except WindowsError, e:
|
||||||
if e.args[0] not in (win32.ERROR_SEM_TIMEOUT,
|
if e.args[0] not in (win32.ERROR_SEM_TIMEOUT,
|
||||||
win32.ERROR_PIPE_BUSY):
|
win32.ERROR_PIPE_BUSY) or _check_timeout(t):
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
|
@ -429,6 +429,11 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- 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.
|
||||||
|
|
||||||
- Issue #7197: Allow unittest.TextTestRunner objects to be pickled and
|
- Issue #7197: Allow unittest.TextTestRunner objects to be pickled and
|
||||||
unpickled. This fixes crashes under Windows when trying to run
|
unpickled. This fixes crashes under Windows when trying to run
|
||||||
test_multiprocessing in verbose mode.
|
test_multiprocessing in verbose mode.
|
||||||
|
|
Loading…
Reference in New Issue