Server Hooks

on_starting

    1. def on_starting(server):
    2. pass

Called just before the master process is initialized.

The callable needs to accept a single instance variable for the Arbiter.

on_reload

    1. def on_reload(server):
    2. pass

Called to recycle workers during a reload via SIGHUP.

The callable needs to accept a single instance variable for the Arbiter.

when_ready

    1. def when_ready(server):
    2. pass

Called just after the server is started.

The callable needs to accept a single instance variable for the Arbiter.

pre_fork

    1. def pre_fork(server, worker):
    2. pass

Called just before a worker is forked.

The callable needs to accept two instance variables for the Arbiter and new Worker.

post_fork

    1. def post_fork(server, worker):
    2. pass

Called just after a worker has been forked.

The callable needs to accept two instance variables for the Arbiter and new Worker.

post_worker_init

    1. def post_worker_init(worker):
    2. pass

Called just after a worker has initialized the application.

The callable needs to accept one instance variable for the initialized Worker.

worker_int

    1. def worker_int(worker):
    2. pass

Called just after a worker exited on SIGINT or SIGQUIT.

The callable needs to accept one instance variable for the initialized Worker.

worker_abort

    1. def worker_abort(worker):
    2. pass

Called when a worker received the SIGABRT signal.

This call generally happens on timeout.

The callable needs to accept one instance variable for the initialized Worker.

pre_exec

    1. def pre_exec(server):
    2. pass

Called just before a new master process is forked.

The callable needs to accept a single instance variable for the Arbiter.

pre_request

    1. def pre_request(worker, req):
    2. worker.log.debug("%s %s" % (req.method, req.path))

Called just before a worker processes the request.

The callable needs to accept two instance variables for the Worker and the Request.

post_request

    1. def post_request(worker, req, environ, resp):
    2. pass

Called after a worker processes the request.

The callable needs to accept two instance variables for the Worker and the Request.

child_exit

    1. def child_exit(server, worker):
    2. pass

Called just after a worker has been exited, in the master process.

The callable needs to accept two instance variables for the Arbiter and the just-exited Worker.

New in version 19.7.

worker_exit

    1. def worker_exit(server, worker):
    2. pass

Called just after a worker has been exited, in the worker process.

The callable needs to accept two instance variables for the Arbiter and the just-exited Worker.

nworkers_changed

    1. def nworkers_changed(server, new_value, old_value):
    2. pass

Called just after num_workers has been changed.

The callable needs to accept an instance variable of the Arbiter and two integers of number of workers after and before change.

If the number of workers is set for the first time, old_value would be None.

on_exit

    1. def on_exit(server):
    2. pass

Called just before exiting Gunicorn.

The callable needs to accept a single instance variable for the Arbiter.