Gunicorn

ConsenSys-Utils slightly enhances gunicorn for better compatibility with its features

Application

class consensys_utils.gunicorn.app.WSGIApplication(loader, *args, **kwargs)[source]

An enhanced gunicorn WSGIApplication including ConsenSys-Utils features

load_config()[source]

This method is used to load the configuration from one or several input(s). Custom Command line, configuration file. You have to override this method in your class.

Config

class consensys_utils.gunicorn.config.Config(usage=None, prog=None)[source]

Gunicorn Configuration that ensures next settings are correctly discovered

  • LoggingConfig()
  • WSGIConfig()

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
setup(cfg)[source]

Setup the logger configuration from .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

setup(cfg)[source]

Setup the logger configuration from .yml file

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.

iterate()[source]

Iterate on WSGI object

run()[source]

Run the main worker loop

At each step of the loop it

  1. Handles entry socket request if available
  2. 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.