gevent.baseserver
– Base class for implementing servers¶BaseServer
(listener, handle=None, spawn='default')[source]¶Bases: object
An abstract base class that implements some common functionality for the servers in gevent.
Parameters: |
|
---|
Changed in version 1.1a1: When the handle function returns from processing a connection, the client socket will be closed. This resolves the non-deterministic closing of the socket, fixing ResourceWarnings under Python 3 and PyPy.
init_socket
()[source]¶If the user initialized the server with an address rather than socket, then this function will create a socket, bind it and put it into listening mode.
It is not supposed to be called by the user, it is called by start()
before starting
the accept loop.
serve_forever
(stop_timeout=None)[source]¶Start the server if it hasn’t been already started and wait until it’s stopped.
start
()[source]¶Start accepting the connections.
If an address was provided in the constructor, then also create a socket, bind it and put it into the listening mode.
stop
(timeout=None)[source]¶Stop accepting the connections and close the listening socket.
If the server uses a pool to spawn the requests, then
stop()
also waits for all the handlers to exit. If there
are still handlers executing after timeout has expired
(default 1 second, stop_timeout
), then the currently
running handlers in the pool are killed.
If the server does not use a pool, then this merely stops accepting connections; any spawned greenlets that are handling requests continue running until they naturally complete.
max_accept
= 100¶Sets the maximum number of consecutive accepts that a process may perform on a single wake up. High values give higher priority to high connection rates, while lower values give higher priority to already established connections. Default is 100. Note, that in case of multiple working processes on the same listening value, it should be set to a lower value. (pywsgi.WSGIServer sets it to 1 when environ[“wsgi.multiprocess”] is true)
min_delay
= 0.01¶the number of seconds to sleep in case there was an error in accept() call for consecutive errors the delay will double until it reaches max_delay when accept() finally succeeds the delay will be reset to min_delay again
server_host
¶IP address that the server is bound to (string).
server_port
¶Port that the server is bound to (an integer).
stop_timeout
= 1¶the default timeout that we wait for the client connections to close in stop()
Next page: gevent.builtins
– gevent friendly implementations of builtin functions