cheroot.connections module

Utilities to manage open connections.

class cheroot.connections.ConnectionManager(server)

Bases: object

Class which manages HTTPConnection objects.

This is for connections which are being kept-alive for follow-up requests.

_from_server_socket(server_socket)
property _num_connections

Return the current number of connections.

Includes any in the readable list or registered with the selector, minus one for the server socket, which is always registered with the selector.

property can_add_keepalive_connection

Flag whether it is allowed to add a new keep-alive connection.

close()

Close all monitored connections.

expire()

Expire least recently used connections.

This happens if there are either too many open connections, or if the connections have been timed out.

This should be called periodically.

get_conn()

Return a HTTPConnection object which is ready to be handled.

A connection returned by this method should be ready for a worker to handle it. If there are no connections ready, None will be returned.

Any connection returned by this method will need to be put back if it should be examined again for another request.

Returns

HTTPConnection instance, or None

Return type

cheroot.server.HTTPConnection

put(conn)

Put idle connection into the ConnectionManager to be managed.

Parameters

conn (cheroot.server.HTTPConnection) – HTTP connection to be managed

cheroot.connections.prevent_socket_inheritance(sock)

Mark the given socket fd as non-inheritable (POSIX).