support for gunicorn (and other pre-forking wsgi servers)

This commit is contained in:
Martin Zimmermann 2013-11-25 13:51:08 +01:00
parent aa65873fa6
commit 896b4f5e33
2 changed files with 18 additions and 12 deletions

View File

@ -33,10 +33,11 @@ dist = pkg_resources.get_distribution("isso")
try: try:
import uwsgi import uwsgi
except ImportError: except ImportError:
uwsgi = None
try: try:
import gevent.monkey; gevent.monkey.patch_all() import gevent.monkey; gevent.monkey.patch_all()
except ImportError: except ImportError:
pass gevent = None
import sys import sys
import os import os
@ -63,7 +64,7 @@ local = Local()
local_manager = LocalManager([local]) local_manager = LocalManager([local])
from isso import db, migrate, wsgi, ext, views from isso import db, migrate, wsgi, ext, views
from isso.core import ThreadedMixin, uWSGIMixin, Config from isso.core import ThreadedMixin, ProcessMixin, uWSGIMixin, Config
from isso.utils import parse, http, JSONRequest, origin from isso.utils import parse, http, JSONRequest, origin
from isso.views import comments from isso.views import comments
@ -141,13 +142,14 @@ class Isso(object):
def make_app(conf=None): def make_app(conf=None):
try: if uwsgi:
import uwsgi class App(Isso, uWSGIMixin):
except ImportError: pass
elif gevent or sys.argv[0].endswith("isso"):
class App(Isso, ThreadedMixin): class App(Isso, ThreadedMixin):
pass pass
else: else:
class App(Isso, uWSGIMixin): class App(Isso, ProcessMixin):
pass pass
isso = App(conf) isso = App(conf)
@ -222,9 +224,5 @@ def main():
raise raise
wsgi.SocketHTTPServer(sock, make_app(conf)).serve_forever() wsgi.SocketHTTPServer(sock, make_app(conf)).serve_forever()
try:
import uwsgi application = make_app(Config.load(os.environ.get('ISSO_SETTINGS')))
except ImportError:
pass
else:
application = make_app(Config.load(os.environ.get('ISSO_SETTINGS')))

View File

@ -214,6 +214,14 @@ class ThreadedMixin(Mixin):
time.sleep(delta) time.sleep(delta)
class ProcessMixin(ThreadedMixin):
def __init__(self, conf):
super(ProcessMixin, self).__init__(conf)
self.lock = multiprocessing.Lock()
class uWSGICache(object): class uWSGICache(object):
"""Uses uWSGI Caching Framework. INI configuration: """Uses uWSGI Caching Framework. INI configuration: