class multiprocessing.connection.Listener([address[, family[, backlog[, authenticate[, authkey]]]]])
A wrapper for a bound socket or Windows named pipe which is ‘listening’ for connections.
address is the address to be used by the bound socket or named pipe of the listener object.
Note
If an address of ‘0.0.0.0’ is used, the address will not be a connectable end point on Windows. If you require a connectable end-point, you should use ‘127.0.0.1’.
family is the type of socket (or named pipe) to use. This can be one of the strings 'AF_INET'
(for a TCP socket), 'AF_UNIX'
(for a Unix domain socket) or 'AF_PIPE'
(for a Windows named pipe). Of these only the first is guaranteed to be available. If family is None
then the family is inferred from the format of address. If address is also None
then a default is chosen. This default is the family which is assumed to be the fastest available. See Address Formats. Note that if family is 'AF_UNIX'
and address is None
then the socket will be created in a private temporary directory created using tempfile.mkstemp()
.
If the listener object uses a socket then backlog (1 by default) is passed to the listen()
method of the socket once it has been bound.
If authenticate is True
(False
by default) or authkey is not None
then digest authentication is used.
If authkey is a byte string then it will be used as the authentication key; otherwise it must be None.
If authkey is None
and authenticate is True
then current_process().authkey
is used as the authentication key. If authkey is None
and authenticate is False
then no authentication is done. If authentication fails then AuthenticationError
is raised. See Authentication keys.
-
accept()
-
Accept a connection on the bound socket or named pipe of the listener object and return a
Connection
object. If authentication is attempted and fails, thenAuthenticationError
is raised.
-
close()
-
Close the bound socket or named pipe of the listener object. This is called automatically when the listener is garbage collected. However it is advisable to call it explicitly.
Listener objects have the following read-only properties:
-
address
-
The address which is being used by the Listener object.
-
last_accepted
-
The address from which the last accepted connection came. If this is unavailable then it is
None
.
New in version 3.3: Listener objects now support the context management protocol – see Context Manager Types. __enter__()
returns the listener object, and __exit__()
calls close()
.
Please login to continue.