Skip to content

Commit 9802e21

Browse files
authored
Merge pull request benoitc#3214 from boxydog/doc_prefork
Document server hooks in a custom application
2 parents 5b68c17 + 0f20019 commit 9802e21

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

docs/source/custom.rst

+19
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ a custom Application:
1616
:start-after: # See the NOTICE for more information
1717
:lines: 2-
1818

19+
Using server hooks
20+
------------------
21+
22+
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:
23+
24+
.. code-block:: python
25+
26+
def pre_fork(server, worker):
27+
print(f"pre-fork server {server} worker {worker}", file=sys.stderr)
28+
29+
# ...
30+
if __name__ == '__main__':
31+
options = {
32+
'bind': '%s:%s' % ('127.0.0.1', '8080'),
33+
'workers': number_of_workers(),
34+
'pre_fork': pre_fork,
35+
}
36+
37+
1938
Direct Usage of Existing WSGI Apps
2039
----------------------------------
2140

0 commit comments

Comments
 (0)