diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index f1f9d087edf7f9..461ffb059f86f1 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -2517,7 +2517,7 @@ multiple connections at the same time. ``'AF_UNIX'`` and address is ``None`` then the socket will be created in a private temporary directory created using :func:`tempfile.mkstemp`. - If the listener object uses a socket then *backlog* (1 by default) is passed + If the listener object uses a socket then *backlog* (None by default) is passed to the :meth:`~socket.socket.listen` method of the socket once it has been bound. diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py index b7e1e132172d02..b712f31fe1a0db 100644 --- a/Lib/multiprocessing/connection.py +++ b/Lib/multiprocessing/connection.py @@ -452,7 +452,7 @@ class Listener(object): This is a wrapper for a bound socket which is 'listening' for connections, or for a Windows named pipe. ''' - def __init__(self, address=None, family=None, backlog=1, authkey=None): + def __init__(self, address=None, family=None, backlog=None, authkey=None): family = family or (address and address_type(address)) \ or default_family address = address or arbitrary_address(family) @@ -597,7 +597,7 @@ class SocketListener(object): ''' Representation of a socket which is bound to an address and listening ''' - def __init__(self, address, family, backlog=1): + def __init__(self, address, family, backlog=None): self._socket = socket.socket(getattr(socket, family)) try: # SO_REUSEADDR has different semantics on Windows (issue #2550). @@ -606,7 +606,10 @@ def __init__(self, address, family, backlog=1): socket.SO_REUSEADDR, 1) self._socket.setblocking(True) self._socket.bind(address) - self._socket.listen(backlog) + if backlog is None: + self._socket.listen() + else: + self._socket.listen(backlog) self._address = self._socket.getsockname() except OSError: self._socket.close() diff --git a/Lib/multiprocessing/managers.py b/Lib/multiprocessing/managers.py index 0f5f9f64c2de9e..ec729c11462463 100644 --- a/Lib/multiprocessing/managers.py +++ b/Lib/multiprocessing/managers.py @@ -146,7 +146,7 @@ class Server(object): public = ['shutdown', 'create', 'accept_connection', 'get_methods', 'debug_info', 'number_of_objects', 'dummy', 'incref', 'decref'] - def __init__(self, registry, address, authkey, serializer): + def __init__(self, registry, address, authkey, serializer, backlog=None): if not isinstance(authkey, bytes): raise TypeError( "Authkey {0!r} is type {1!s}, not bytes".format( @@ -156,7 +156,7 @@ def __init__(self, registry, address, authkey, serializer): Listener, Client = listener_client[serializer] # do authentication later - self.listener = Listener(address=address, backlog=128) + self.listener = Listener(address=address, backlog=backlog) self.address = self.listener.address self.id_to_obj = {'0': (None, ())} diff --git a/Misc/NEWS.d/next/Library/2024-07-22-02-19-16.gh-issue-88321.G42EBO.rst b/Misc/NEWS.d/next/Library/2024-07-22-02-19-16.gh-issue-88321.G42EBO.rst new file mode 100644 index 00000000000000..cc77fd8dffd29a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-07-22-02-19-16.gh-issue-88321.G42EBO.rst @@ -0,0 +1 @@ +Add backlog arg for multiprocessing manager server