summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-11-13 22:39:40 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-11-13 22:39:40 (GMT)
commit4def51567d11804bb95d9e1801eba15b9da38a0e (patch)
tree12cd59ffcda9d860083e090e57083358acbe84c3
parentca154091950023d209819484d2d5c51ddcc1e882 (diff)
downloadcpython-4def51567d11804bb95d9e1801eba15b9da38a0e.zip
cpython-4def51567d11804bb95d9e1801eba15b9da38a0e.tar.gz
cpython-4def51567d11804bb95d9e1801eba15b9da38a0e.tar.bz2
Merged revisions 76247 via svnmerge from
svn+ssh://pythondev@svn.python.org/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://pythondev@svn.python.org/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. ........ ................
-rw-r--r--Lib/multiprocessing/connection.py15
-rw-r--r--Misc/NEWS5
2 files changed, 18 insertions, 2 deletions
diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py
index 5e94fed..b632e93 100644
--- a/Lib/multiprocessing/connection.py
+++ b/Lib/multiprocessing/connection.py
@@ -27,6 +27,8 @@ from multiprocessing.forking import duplicate, close
#
BUFSIZE = 8192
+# A very generous timeout when it comes to local connections...
+CONNECTION_TIMEOUT = 20.
_mmap_counter = itertools.count()
@@ -41,6 +43,13 @@ if sys.platform == 'win32':
default_family = '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)
s = socket.socket( getattr(socket, family) )
+ t = _init_timeout()
while 1:
try:
s.connect(address)
except socket.error as 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)
raise
time.sleep(0.01)
@@ -322,6 +332,7 @@ if sys.platform == 'win32':
'''
Return a connection object connected to the pipe given by `address`
'''
+ t = _init_timeout()
while 1:
try:
win32.WaitNamedPipe(address, 1000)
@@ -331,7 +342,7 @@ if sys.platform == 'win32':
)
except WindowsError as e:
if e.args[0] not in (win32.ERROR_SEM_TIMEOUT,
- win32.ERROR_PIPE_BUSY):
+ win32.ERROR_PIPE_BUSY) or _check_timeout(t):
raise
else:
break
diff --git a/Misc/NEWS b/Misc/NEWS
index fd56e89..8a7b78d 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -40,6 +40,11 @@ Core and Builtins
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 #7282: Fix a memory leak when an RLock was used in a thread other
than those started through `threading.Thread` (for example, using
`_thread.start_new_thread()`).