fixed gevent workers
This commit is contained in:
+34
-26
@@ -33,7 +33,7 @@ class Servers:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def wsgiref(app, address, **options): # pragma: no cover
|
def wsgiref(app, address, **options): # pragma: no cover
|
||||||
from wsgiref.simple_server import make_server, WSGIRequestHandler
|
from wsgiref.simple_server import make_server, WSGIRequestHandler
|
||||||
|
options = {}
|
||||||
class QuietHandler(WSGIRequestHandler):
|
class QuietHandler(WSGIRequestHandler):
|
||||||
def log_request(*args, **kw):
|
def log_request(*args, **kw):
|
||||||
pass
|
pass
|
||||||
@@ -71,6 +71,7 @@ class Servers:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def paste(app, address, **options):
|
def paste(app, address, **options):
|
||||||
|
options = {}
|
||||||
from paste import httpserver
|
from paste import httpserver
|
||||||
from paste.translogger import TransLogger
|
from paste.translogger import TransLogger
|
||||||
httpserver.serve(app, host=address[0], port=address[1], **options)
|
httpserver.serve(app, host=address[0], port=address[1], **options)
|
||||||
@@ -90,10 +91,12 @@ class Servers:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def gevent(app, address, **options):
|
def gevent(app, address, **options):
|
||||||
|
options = options['options']
|
||||||
|
workers = options.workers
|
||||||
from gevent import pywsgi
|
from gevent import pywsgi
|
||||||
from gevent.pool import Pool
|
from gevent.pool import Pool
|
||||||
pywsgi.WSGIServer(address, app, spawn='workers' in options and Pool(
|
pywsgi.WSGIServer(address, app, spawn=workers and Pool(
|
||||||
int(options.workers)) or 'default').serve_forever()
|
int(options.workers)) or 'default', log=None).serve_forever()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def bjoern(app, address, **options):
|
def bjoern(app, address, **options):
|
||||||
@@ -130,6 +133,7 @@ class Servers:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def gunicorn(app, address, **options):
|
def gunicorn(app, address, **options):
|
||||||
|
options = {}
|
||||||
from gunicorn.app.base import Application
|
from gunicorn.app.base import Application
|
||||||
config = {'bind': "%s:%d" % address}
|
config = {'bind': "%s:%d" % address}
|
||||||
config.update(options)
|
config.update(options)
|
||||||
@@ -176,27 +180,6 @@ class Servers:
|
|||||||
s = wsgi.WSGIServer(callable=app, bind="%s:%d" % address)
|
s = wsgi.WSGIServer(callable=app, bind="%s:%d" % address)
|
||||||
s.start()
|
s.start()
|
||||||
|
|
||||||
def run(servername, ip, port, softcron=True, logging=False, profiler=None):
|
|
||||||
if servername == 'gevent':
|
|
||||||
from gevent import monkey
|
|
||||||
monkey.patch_all()
|
|
||||||
elif servername == 'eventlet':
|
|
||||||
import eventlet
|
|
||||||
eventlet.monkey_patch()
|
|
||||||
|
|
||||||
import gluon.main
|
|
||||||
|
|
||||||
if logging:
|
|
||||||
application = gluon.main.appfactory(wsgiapp=gluon.main.wsgibase,
|
|
||||||
logfilename='httpserver.log',
|
|
||||||
profiler_dir=profiler)
|
|
||||||
else:
|
|
||||||
application = gluon.main.wsgibase
|
|
||||||
if softcron:
|
|
||||||
from gluon.settings import global_settings
|
|
||||||
global_settings.web2py_crontype = 'soft'
|
|
||||||
getattr(Servers, servername)(application, (ip, int(port)))
|
|
||||||
|
|
||||||
|
|
||||||
def mongrel2_handler(application, conn, debug=False):
|
def mongrel2_handler(application, conn, debug=False):
|
||||||
"""
|
"""
|
||||||
@@ -303,6 +286,30 @@ def mongrel2_handler(application, conn, debug=False):
|
|||||||
req, data, code=code, status=status, headers=headers)
|
req, data, code=code, status=status, headers=headers)
|
||||||
|
|
||||||
|
|
||||||
|
def run(servername, ip, port, softcron=True, logging=False, profiler=None,
|
||||||
|
options=None):
|
||||||
|
if servername == 'gevent':
|
||||||
|
from gevent import monkey
|
||||||
|
monkey.patch_all()
|
||||||
|
elif servername == 'eventlet':
|
||||||
|
import eventlet
|
||||||
|
eventlet.monkey_patch()
|
||||||
|
|
||||||
|
import gluon.main
|
||||||
|
|
||||||
|
if logging:
|
||||||
|
application = gluon.main.appfactory(wsgiapp=gluon.main.wsgibase,
|
||||||
|
logfilename='httpserver.log',
|
||||||
|
profiler_dir=profiler)
|
||||||
|
else:
|
||||||
|
application = gluon.main.wsgibase
|
||||||
|
if softcron:
|
||||||
|
from gluon.settings import global_settings
|
||||||
|
global_settings.web2py_crontype = 'soft'
|
||||||
|
getattr(Servers, servername)(application, (ip, int(port)), options=options)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
usage = "python anyserver.py -s tornado -i 127.0.0.1 -p 8000 -l -P"
|
usage = "python anyserver.py -s tornado -i 127.0.0.1 -p 8000 -l -P"
|
||||||
try:
|
try:
|
||||||
@@ -339,14 +346,15 @@ def main():
|
|||||||
help='port number')
|
help='port number')
|
||||||
parser.add_option('-w',
|
parser.add_option('-w',
|
||||||
'--workers',
|
'--workers',
|
||||||
default='',
|
default=None,
|
||||||
dest='workers',
|
dest='workers',
|
||||||
help='number of workers number')
|
help='number of workers number')
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
print 'starting %s on %s:%s...' % (
|
print 'starting %s on %s:%s...' % (
|
||||||
options.server, options.ip, options.port)
|
options.server, options.ip, options.port)
|
||||||
run(options.server, options.ip, options.port,
|
run(options.server, options.ip, options.port,
|
||||||
logging=options.logging, profiler=options.profiler_dir)
|
logging=options.logging, profiler=options.profiler_dir,
|
||||||
|
options=options)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user