Gunicorn¶
ConsenSys-Utils slightly enhances gunicorn for better compatibility with its features
Application¶
Config¶
Logging¶
-
class
consensys_utils.gunicorn.logging.
Logger
(cfg)[source]¶ Enrich Gunicorn logger class
In particular it overrides the following methods
- setup to load logging configuration from a .yml file
-
class
consensys_utils.gunicorn.logging.
RequestIDLogger
(*args, **kwargs)[source]¶ Gunicorn logger that handles Request ID header
-
access
(resp, req, environ, request_time)[source]¶ See http://httpd.apache.org/docs/2.0/logs.html#combined for format details
-
Workers¶
-
class
consensys_utils.gunicorn.workers.
SyncIteratingWorker
(age, ppid, sockets, app, timeout, cfg, log)[source]¶ A Gunicorn synchronous worker that allows to run an iterable WSGI application.
It allows to run a loop process that iterates over a WSGI application object while allowing to process HTTP requests.
Since the worker is synchronous it is thread safe to modify the WSGI object either when iterating or when handling an HTTP request.
Remark
Such a worker should not be considered highly performing as HTTP server but for dealing with a few requests to control the iterable WSGI application it is well suited.
-
handle
(listener, client, address)[source]¶ Handle a request
Method is almost identical to
gunicorn.workers.sync.SyncWorker()
one.We need to overide this method because we use non blocking socket connections thus we are more sensitive to
errno.EAGAIN()
errors.
-
run
()[source]¶ Run the main worker loop
At each step of the loop it
- Handles entry socket request if available
- Iterate on the WSGI iterable object
If a
consensys_utils.exceptions.PauseIteration()
is caught when iterating on the WSGI object then the loop waits by entering a stale state freeing CPU usage.Receiving an HTTP request instantaneously gets the loop out of stale state.
-