add server hook "on_starting" to allow socket patching to allow gevent worker reloading.

This commit is contained in:
Neil Chintomby 2011-03-14 14:37:19 -04:00 committed by benoitc
parent 974698671a
commit 06987d3702
3 changed files with 22 additions and 0 deletions

View File

@ -3,6 +3,11 @@ import os
import signal
import sys
def on_starting(server):
# use server hook to patch socket to allow worker reloading
from gevent import monkey
monkey.patch_socket()
def when_ready(server):
def monitor():
modify_times = {}

View File

@ -109,6 +109,7 @@ class Arbiter(object):
"""\
Initialize the arbiter. Start listening and set pidfile if needed.
"""
self.cfg.on_starting(self)
self.pid = os.getpid()
self.init_signals()
if not self.LISTENER:

View File

@ -703,3 +703,19 @@ class WorkerExit(Setting):
The callable needs to accept two instance variables for the Arbiter and
the just-exited Worker.
"""
class OnStarting(Setting):
name = "on_starting"
section = "Server Hooks"
validator = validate_callable(1)
type = "callable"
def def_on_starting(server):
pass
def_on_starting = staticmethod(def_on_starting)
default = def_on_starting
desc = """\
Called just before the master process is initialized.
The callable needs to accept a single instance variable for the Arbiter.
"""