Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed gevent workers

  • Loading branch information...
commit b464d3185e2ec4b2a3559eb3cc77d306c0a9a36e 1 parent cfb68ff
@niphlod niphlod authored
Showing with 34 additions and 26 deletions.
  1. +34 −26 anyserver.py
View
60 anyserver.py
@@ -33,7 +33,7 @@ def flup(app, address, **options):
@staticmethod
def wsgiref(app, address, **options): # pragma: no cover
from wsgiref.simple_server import make_server, WSGIRequestHandler
-
+ options = {}
class QuietHandler(WSGIRequestHandler):
def log_request(*args, **kw):
pass
@@ -71,6 +71,7 @@ def rocket_with_repoze_profiler(app, address, **options):
@staticmethod
def paste(app, address, **options):
+ options = {}
from paste import httpserver
from paste.translogger import TransLogger
httpserver.serve(app, host=address[0], port=address[1], **options)
@@ -90,10 +91,12 @@ def app(environ, start_response):
@staticmethod
def gevent(app, address, **options):
+ options = options['options']
+ workers = options.workers
from gevent import pywsgi
from gevent.pool import Pool
- pywsgi.WSGIServer(address, app, spawn='workers' in options and Pool(
- int(options.workers)) or 'default').serve_forever()
+ pywsgi.WSGIServer(address, app, spawn=workers and Pool(
+ int(options.workers)) or 'default', log=None).serve_forever()
@staticmethod
def bjoern(app, address, **options):
@@ -130,6 +133,7 @@ def diesel(app, address, **options):
@staticmethod
def gunicorn(app, address, **options):
+ options = {}
from gunicorn.app.base import Application
config = {'bind': "%s:%d" % address}
config.update(options)
@@ -176,27 +180,6 @@ def pulsar(app, address, **options):
s = wsgi.WSGIServer(callable=app, bind="%s:%d" % address)
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):
"""
@@ -303,6 +286,30 @@ def mongrel2_handler(application, conn, debug=False):
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():
usage = "python anyserver.py -s tornado -i 127.0.0.1 -p 8000 -l -P"
try:
@@ -339,14 +346,15 @@ def main():
help='port number')
parser.add_option('-w',
'--workers',
- default='',
+ default=None,
dest='workers',
help='number of workers number')
(options, args) = parser.parse_args()
print 'starting %s on %s:%s...' % (
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__':
main()
Please sign in to comment.
Something went wrong with that request. Please try again.