From 992ca5278ec1d7529c4aeedfed74051890feac1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Fran=C3=A7ois=20Natali?= Date: Sat, 4 Feb 2012 14:55:53 +0100 Subject: [PATCH 1/2] Issue #8184: Fix a potential file descriptor leak when a multiprocessing.Connection socket can't be bound. --- Lib/multiprocessing/connection.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py index d6c23fb0ecd..df00f1d9066 100644 --- a/Lib/multiprocessing/connection.py +++ b/Lib/multiprocessing/connection.py @@ -249,10 +249,14 @@ class SocketListener(object): ''' def __init__(self, address, family, backlog=1): self._socket = socket.socket(getattr(socket, family)) - self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - self._socket.bind(address) - self._socket.listen(backlog) - self._address = self._socket.getsockname() + try: + self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + self._socket.bind(address) + self._socket.listen(backlog) + self._address = self._socket.getsockname() + except socket.error: + self._socket.close() + raise self._family = family self._last_accepted = None From f51ebf94bb527f66331f92ac00f66f529ded73f0 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sat, 4 Feb 2012 09:55:52 -0500 Subject: [PATCH 2/2] threading primitives now have timeouts --- Doc/library/multiprocessing.rst | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index 3d83114f7a2..ebc41f8da9b 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -876,14 +876,6 @@ object -- see :ref:`multiprocessing-managers`. .. note:: - The :meth:`acquire` method of :class:`BoundedSemaphore`, :class:`Lock`, - :class:`RLock` and :class:`Semaphore` has a timeout parameter not supported - by the equivalents in :mod:`threading`. The signature is - ``acquire(block=True, timeout=None)`` with keyword parameters being - acceptable. If *block* is ``True`` and *timeout* is not ``None`` then it - specifies a timeout in seconds. If *block* is ``False`` then *timeout* is - ignored. - On Mac OS X, ``sem_timedwait`` is unsupported, so calling ``acquire()`` with a timeout will emulate that function's behavior using a sleeping loop.