From 0f20019113c06edb9ae96602c8f83b8024c7e6af Mon Sep 17 00:00:00 2001 From: boxydog <93335439+boxydog@users.noreply.github.com> Date: Sat, 18 May 2024 14:20:42 -0500 Subject: [PATCH] Document server hooks in a custom application --- docs/source/custom.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/source/custom.rst b/docs/source/custom.rst index 0fb39250..90f74209 100644 --- a/docs/source/custom.rst +++ b/docs/source/custom.rst @@ -16,6 +16,25 @@ a custom Application: :start-after: # See the NOTICE for more information :lines: 2- +Using server hooks +------------------ + +If you wish to include server hooks in your custom application, you can specify a function in the config options. Here is an example with the `pre_fork` hook: + +.. code-block:: python + + def pre_fork(server, worker): + print(f"pre-fork server {server} worker {worker}", file=sys.stderr) + + # ... + if __name__ == '__main__': + options = { + 'bind': '%s:%s' % ('127.0.0.1', '8080'), + 'workers': number_of_workers(), + 'pre_fork': pre_fork, + } + + Direct Usage of Existing WSGI Apps ----------------------------------