mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
rewrite ggevent2 workerr to support last gevent 0.13. a lot more stable
and faster than it was. gevent 0.13 give new streaming possibilities and keepalive.
This commit is contained in:
parent
cea5a8c6b5
commit
3be6826ea1
@ -10,62 +10,48 @@ from gevent import core
|
||||
from gevent import monkey
|
||||
monkey.noisy = False
|
||||
from gevent.pool import Pool
|
||||
from gevent import wsgi
|
||||
from gevent import pywsgi
|
||||
|
||||
import gunicorn
|
||||
from gunicorn.workers.base import Worker
|
||||
|
||||
class WSGIHandler(wsgi.WSGIHandler):
|
||||
class WSGIHandler(pywsgi.WSGIHandler):
|
||||
def log_request(self, *args):
|
||||
pass
|
||||
|
||||
class GEvent2Worker(Worker):
|
||||
|
||||
class WSGIServer(pywsgi.WSGIServer):
|
||||
base_env = {'GATEWAY_INTERFACE': 'CGI/1.1',
|
||||
'SERVER_SOFTWARE': 'gevent/%s gunicorn/%s' % (gevent.__version__,
|
||||
gunicorn.__version__),
|
||||
'SCRIPT_NAME': '',
|
||||
'wsgi.version': (1, 0),
|
||||
'wsgi.multithread': False,
|
||||
'wsgi.multiprocess': False,
|
||||
'wsgi.run_once': False}
|
||||
|
||||
|
||||
|
||||
base_env = {
|
||||
'GATEWAY_INTERFACE': 'CGI/1.1',
|
||||
'SERVER_SOFTWARE': 'gevent/%s gunicorn/%s' % (gevent.__version__,
|
||||
gunicorn.__version__),
|
||||
'SCRIPT_NAME': '',
|
||||
'wsgi.version': (1, 0),
|
||||
'wsgi.url_scheme': 'http',
|
||||
'wsgi.multithread': False,
|
||||
'wsgi.multiprocess': True,
|
||||
'wsgi.run_once': False
|
||||
}
|
||||
class GEvent2Worker(Worker):
|
||||
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(GEvent2Worker, self).__init__(*args, **kwargs)
|
||||
self.worker_connections = self.cfg.worker_connections
|
||||
self.pool = None
|
||||
|
||||
@classmethod
|
||||
def setup(cls):
|
||||
from gevent import monkey
|
||||
monkey.patch_all(dns=False)
|
||||
|
||||
def handle_request(self, req):
|
||||
self.pool.spawn(self.handle, req)
|
||||
|
||||
def handle(self, req):
|
||||
handle = WSGIHandler(req)
|
||||
handle.handle(self)
|
||||
|
||||
def run(self):
|
||||
self.socket.setblocking(1)
|
||||
env = self.base_env.copy()
|
||||
pool = Pool(self.worker_connections)
|
||||
|
||||
env.update({
|
||||
'SERVER_NAME': self.address[0],
|
||||
'SERVER_PORT': str(self.address[1])
|
||||
})
|
||||
self.base_env = env
|
||||
server = WSGIServer(self.socket, application=self.wsgi,
|
||||
spawn=pool, handler_class=WSGIHandler)
|
||||
|
||||
http = core.http()
|
||||
http.set_gencb(self.handle_request)
|
||||
self.pool = Pool(self.worker_connections)
|
||||
|
||||
self.application = self.wsgi
|
||||
acceptor = gevent.spawn(http.accept, self.socket.fileno())
|
||||
acceptor = gevent.spawn(server.serve_forever)
|
||||
|
||||
try:
|
||||
while self.alive:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user