Skip to content

Commit

Permalink
monkey patch in the worker
Browse files Browse the repository at this point in the history
this change move the monkey patching from the aribiter to the worker so we make sure the supervision won't be altered.

fix benoitc#478
  • Loading branch information
benoitc committed Nov 4, 2013
1 parent f43d299 commit f2920bf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
17 changes: 12 additions & 5 deletions gunicorn/workers/geventlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
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
Expand All @@ -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()

Expand Down Expand Up @@ -84,3 +86,8 @@ def run(self):
if te != t:
raise
[a.kill() for a in acceptors]

def init_process(self):
# monkey patch here
self.patch()
super(EventletWorker, self).init_process()
14 changes: 12 additions & 2 deletions gunicorn/workers/ggevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -157,13 +156,24 @@ def handle_request(self, *args):
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
gevent.core.dns_shutdown(fail_requests=1)
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):

Expand Down

0 comments on commit f2920bf

Please sign in to comment.