monkey patch in the worker

this change move the monkey patching from the aribiter to the worker so we make sure the supervision won't be altered.

fix #478
This commit is contained in:
benoitc 2013-11-04 14:26:05 +01:00
parent f43d299503
commit f2920bfcda
2 changed files with 24 additions and 7 deletions

View File

@ -10,6 +10,12 @@ try:
import eventlet
except ImportError:
raise RuntimeError("You need eventlet installed to use this worker.")
# validate the eventlet version
if eventlet.version_info < (0, 9, 7):
raise RuntimeError("You need eventlet >= 0.9.7")
from eventlet import hubs
from eventlet.greenio import GreenSocket
from eventlet.hubs import trampoline
@ -35,11 +41,7 @@ def patch_sendfile():
class EventletWorker(AsyncWorker):
@classmethod
def setup(cls):
import eventlet
if eventlet.version_info < (0, 9, 7):
raise RuntimeError("You need eventlet >= 0.9.7")
def patch(self):
eventlet.monkey_patch(os=False)
patch_sendfile()
@ -84,3 +86,8 @@ class EventletWorker(AsyncWorker):
if te != t:
raise
[a.kill() for a in acceptors]
def init_process(self):
# monkey patch here
self.patch()
super(EventletWorker, self).init_process()

View File

@ -63,8 +63,7 @@ class GeventWorker(AsyncWorker):
server_class = None
wsgi_handler = None
@classmethod
def setup(cls):
def patch(cls):
from gevent import monkey
monkey.noisy = False
monkey.patch_all()
@ -157,6 +156,9 @@ class GeventWorker(AsyncWorker):
if gevent.version_info[0] == 0:
def init_process(self):
# monkey patch here
self.patch()
#gevent 0.13 and older doesn't reinitialize dns for us after forking
#here's the workaround
import gevent.core
@ -164,6 +166,14 @@ class GeventWorker(AsyncWorker):
gevent.core.dns_init()
super(GeventWorker, self).init_process()
else:
def init_process(self):
# monkey patch here
self.patch()
# then initialize the process
super(GeventWorker, self).init_process()
class GeventResponse(object):