Merge pull request #555 from seatgeek/post-init

Add post-init hook for workers
This commit is contained in:
Randall Leeds 2013-06-20 16:01:06 -07:00
commit cee5c57abc
3 changed files with 33 additions and 0 deletions

View File

@ -561,6 +561,19 @@ Called just after a worker has been forked.
The callable needs to accept two instance variables for the Arbiter and
new Worker.
post_init
~~~~~~~~~
* ::
def post_init(worker):
pass
Called just after a worker has initialized the application.
The callable needs to accept one instance variable for the initialized
Worker.
pre_exec
~~~~~~~~

View File

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

View File

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