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
|
from gevent import monkey
|
||||||
monkey.noisy = False
|
monkey.noisy = False
|
||||||
from gevent.pool import Pool
|
from gevent.pool import Pool
|
||||||
from gevent import wsgi
|
from gevent import pywsgi
|
||||||
|
|
||||||
import gunicorn
|
import gunicorn
|
||||||
from gunicorn.workers.base import Worker
|
from gunicorn.workers.base import Worker
|
||||||
|
|
||||||
class WSGIHandler(wsgi.WSGIHandler):
|
class WSGIHandler(pywsgi.WSGIHandler):
|
||||||
def log_request(self, *args):
|
def log_request(self, *args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
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}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class GEvent2Worker(Worker):
|
class GEvent2Worker(Worker):
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(GEvent2Worker, self).__init__(*args, **kwargs)
|
super(GEvent2Worker, self).__init__(*args, **kwargs)
|
||||||
self.worker_connections = self.cfg.worker_connections
|
self.worker_connections = self.cfg.worker_connections
|
||||||
self.pool = None
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setup(cls):
|
def setup(cls):
|
||||||
from gevent import monkey
|
from gevent import monkey
|
||||||
monkey.patch_all(dns=False)
|
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):
|
def run(self):
|
||||||
self.socket.setblocking(1)
|
self.socket.setblocking(1)
|
||||||
env = self.base_env.copy()
|
pool = Pool(self.worker_connections)
|
||||||
|
|
||||||
env.update({
|
server = WSGIServer(self.socket, application=self.wsgi,
|
||||||
'SERVER_NAME': self.address[0],
|
spawn=pool, handler_class=WSGIHandler)
|
||||||
'SERVER_PORT': str(self.address[1])
|
|
||||||
})
|
|
||||||
self.base_env = env
|
|
||||||
|
|
||||||
http = core.http()
|
acceptor = gevent.spawn(server.serve_forever)
|
||||||
http.set_gencb(self.handle_request)
|
|
||||||
self.pool = Pool(self.worker_connections)
|
|
||||||
|
|
||||||
self.application = self.wsgi
|
|
||||||
acceptor = gevent.spawn(http.accept, self.socket.fileno())
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while self.alive:
|
while self.alive:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user