Merge pull request #3214 from boxydog/doc_prefork

Document server hooks in a custom application
This commit is contained in:
Benoit Chesneau 2024-05-22 04:21:04 +02:00 committed by GitHub
commit 9802e21f77
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
----------------------------------