mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
monleypatch sendfile for the eventlet worker
makesure sendfile isn't blocking on eventlet
This commit is contained in:
parent
25094605cf
commit
1eceed0ad5
@ -12,9 +12,26 @@ except ImportError:
|
||||
raise RuntimeError("You need eventlet installed to use this worker.")
|
||||
from eventlet import hubs
|
||||
from eventlet.greenio import GreenSocket
|
||||
from eventlet.hubs import trampoline
|
||||
|
||||
from gunicorn.http.wsgi import sendfile as o_sendfile
|
||||
from gunicorn.workers.async import AsyncWorker
|
||||
|
||||
def _eventlet_sendfile(fdout, fdin, offset, nbytes):
|
||||
while True:
|
||||
try:
|
||||
return o_sendfile(fdout, fdin, offset, nbytes)
|
||||
except OSError as e:
|
||||
if e.args[0] == errno.EAGAIN:
|
||||
trampoline(fdout, write=True)
|
||||
else:
|
||||
raise
|
||||
|
||||
def patch_sendfile():
|
||||
from gunicorn.http import wsgi
|
||||
|
||||
if o_sendfile is not None:
|
||||
setattr(wsgi, "sendfile", _eventlet_sendfile)
|
||||
|
||||
class EventletWorker(AsyncWorker):
|
||||
|
||||
@ -24,6 +41,7 @@ class EventletWorker(AsyncWorker):
|
||||
if eventlet.version_info < (0, 9, 7):
|
||||
raise RuntimeError("You need eventlet >= 0.9.7")
|
||||
eventlet.monkey_patch(os=False)
|
||||
patch_sendfile()
|
||||
|
||||
def init_process(self):
|
||||
hubs.use_hub()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user