mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Add post-init hook for workers
Allows a config specifying a function after a worker has been initialized and before the run loop
This commit is contained in:
parent
e77d47cb97
commit
0ae7fd760d
@ -1162,6 +1162,24 @@ class Postfork(Setting):
|
||||
"""
|
||||
|
||||
|
||||
class Postinit(Setting):
|
||||
name = "post_init"
|
||||
section = "Server Hooks"
|
||||
validator = validate_callable(1)
|
||||
type = six.callable
|
||||
|
||||
def post_init(worker):
|
||||
pass
|
||||
|
||||
default = staticmethod(post_init)
|
||||
desc = """\
|
||||
Called just after a worker has initialized the application.
|
||||
|
||||
The callable needs to accept one instance variable for the initialized
|
||||
Worker.
|
||||
"""
|
||||
|
||||
|
||||
class PreExec(Setting):
|
||||
name = "pre_exec"
|
||||
section = "Server Hooks"
|
||||
|
||||
@ -99,6 +99,8 @@ class Worker(object):
|
||||
|
||||
self.wsgi = self.app.wsgi()
|
||||
|
||||
self.cfg.post_init(self)
|
||||
|
||||
# Enter main run loop
|
||||
self.booted = True
|
||||
self.run()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user