Utilities to manage open connections.
- class cheroot.connections.ConnectionManager(server)#
Class which manages HTTPConnection objects.
This is for connections which are being kept-alive for follow-up requests.
Expire least recently used connections.
threshold (float) – Connections that have not been used within this duration (in seconds), are considered expired and are closed and removed.
This should be called periodically.
- property _num_connections#
Return the current number of connections.
Includes all connections registered with the selector, minus one for the server socket, which is always registered with the selector.
Clean up the resources of any broken connections.
This method attempts to detect any connections in an invalid state, unregisters them from the selector and closes the file descriptors of the corresponding network sockets where possible.
Run connection handler loop until stop was requested.
expiration_interval (float) – Interval, in seconds, at which connections will be checked for expiration.
select()timeout to assure expired connections are closed in time.
On Windows cap the timeout to 0.05 seconds as
select()does not return when a socket is ready.
- property can_add_keepalive_connection#
Flag whether it is allowed to add a new keep-alive connection.
Close all monitored connections.
Put idle connection into the ConnectionManager to be managed.
conn (cheroot.server.HTTPConnection) – HTTP connection to be managed
Run the connections selector indefinitely.
- expiration_interval (float): Interval, in seconds, at which
connections will be checked for expiration.
Connections that are ready to process are submitted via self.server.process_conn()
Connections submitted for processing must be
put()back if they should be examined again for another request.
Can be shut down by calling
Stop the selector loop in run() synchronously.
May take up to half a second.
- class cheroot.connections._ThreadsafeSelector#
Thread-safe wrapper around a DefaultSelector.
- There are 2 thread contexts in which it may be accessed:
the selector thread
one of the worker threads in workers/threadpool.py
- The expected read/write patterns are:
iter(): selector thread
register(): selector thread and threadpool, via
unregister(): selector thread only
Notably, this means
_ThreadsafeSelectornever needs to worry that connections will be removed behind its back.
The lock is held when iterating or modifying the selector but is not required when
Close the selector.
- property connections#
Retrieve connections registered with the selector.
- register(fileobj, events, data=None)#
fileobjwith the selector.
Return socket fd and data pairs from selectors.select call.
- Returns entries ready to read in the form:
fileobjfrom the selector.
Mark the given socket fd as non-inheritable (POSIX).