mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
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:
parent
f43d299503
commit
f2920bfcda
@ -10,6 +10,12 @@ try:
|
|||||||
import eventlet
|
import eventlet
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise RuntimeError("You need eventlet installed to use this worker.")
|
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 import hubs
|
||||||
from eventlet.greenio import GreenSocket
|
from eventlet.greenio import GreenSocket
|
||||||
from eventlet.hubs import trampoline
|
from eventlet.hubs import trampoline
|
||||||
@ -35,11 +41,7 @@ def patch_sendfile():
|
|||||||
|
|
||||||
class EventletWorker(AsyncWorker):
|
class EventletWorker(AsyncWorker):
|
||||||
|
|
||||||
@classmethod
|
def patch(self):
|
||||||
def setup(cls):
|
|
||||||
import eventlet
|
|
||||||
if eventlet.version_info < (0, 9, 7):
|
|
||||||
raise RuntimeError("You need eventlet >= 0.9.7")
|
|
||||||
eventlet.monkey_patch(os=False)
|
eventlet.monkey_patch(os=False)
|
||||||
patch_sendfile()
|
patch_sendfile()
|
||||||
|
|
||||||
@ -84,3 +86,8 @@ class EventletWorker(AsyncWorker):
|
|||||||
if te != t:
|
if te != t:
|
||||||
raise
|
raise
|
||||||
[a.kill() for a in acceptors]
|
[a.kill() for a in acceptors]
|
||||||
|
|
||||||
|
def init_process(self):
|
||||||
|
# monkey patch here
|
||||||
|
self.patch()
|
||||||
|
super(EventletWorker, self).init_process()
|
||||||
|
|||||||
@ -63,8 +63,7 @@ class GeventWorker(AsyncWorker):
|
|||||||
server_class = None
|
server_class = None
|
||||||
wsgi_handler = None
|
wsgi_handler = None
|
||||||
|
|
||||||
@classmethod
|
def patch(cls):
|
||||||
def setup(cls):
|
|
||||||
from gevent import monkey
|
from gevent import monkey
|
||||||
monkey.noisy = False
|
monkey.noisy = False
|
||||||
monkey.patch_all()
|
monkey.patch_all()
|
||||||
@ -157,6 +156,9 @@ class GeventWorker(AsyncWorker):
|
|||||||
if gevent.version_info[0] == 0:
|
if gevent.version_info[0] == 0:
|
||||||
|
|
||||||
def init_process(self):
|
def init_process(self):
|
||||||
|
# monkey patch here
|
||||||
|
self.patch()
|
||||||
|
|
||||||
#gevent 0.13 and older doesn't reinitialize dns for us after forking
|
#gevent 0.13 and older doesn't reinitialize dns for us after forking
|
||||||
#here's the workaround
|
#here's the workaround
|
||||||
import gevent.core
|
import gevent.core
|
||||||
@ -164,6 +166,14 @@ class GeventWorker(AsyncWorker):
|
|||||||
gevent.core.dns_init()
|
gevent.core.dns_init()
|
||||||
super(GeventWorker, self).init_process()
|
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):
|
class GeventResponse(object):
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user