From 896b4f5e33d8df2cc84b09c57de51dc1db1a1667 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Mon, 25 Nov 2013 13:51:08 +0100 Subject: [PATCH] support for gunicorn (and other pre-forking wsgi servers) --- isso/__init__.py | 22 ++++++++++------------ isso/core.py | 8 ++++++++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/isso/__init__.py b/isso/__init__.py index 0e7f092..6e8b2e4 100644 --- a/isso/__init__.py +++ b/isso/__init__.py @@ -33,10 +33,11 @@ dist = pkg_resources.get_distribution("isso") try: import uwsgi except ImportError: + uwsgi = None try: import gevent.monkey; gevent.monkey.patch_all() except ImportError: - pass + gevent = None import sys import os @@ -63,7 +64,7 @@ local = Local() local_manager = LocalManager([local]) 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.views import comments @@ -141,13 +142,14 @@ class Isso(object): def make_app(conf=None): - try: - import uwsgi - except ImportError: + if uwsgi: + class App(Isso, uWSGIMixin): + pass + elif gevent or sys.argv[0].endswith("isso"): class App(Isso, ThreadedMixin): pass else: - class App(Isso, uWSGIMixin): + class App(Isso, ProcessMixin): pass isso = App(conf) @@ -222,9 +224,5 @@ def main(): raise wsgi.SocketHTTPServer(sock, make_app(conf)).serve_forever() -try: - import uwsgi -except ImportError: - pass -else: - application = make_app(Config.load(os.environ.get('ISSO_SETTINGS'))) + +application = make_app(Config.load(os.environ.get('ISSO_SETTINGS'))) diff --git a/isso/core.py b/isso/core.py index 2b584f7..e030685 100644 --- a/isso/core.py +++ b/isso/core.py @@ -214,6 +214,14 @@ class ThreadedMixin(Mixin): time.sleep(delta) +class ProcessMixin(ThreadedMixin): + + def __init__(self, conf): + + super(ProcessMixin, self).__init__(conf) + self.lock = multiprocessing.Lock() + + class uWSGICache(object): """Uses uWSGI Caching Framework. INI configuration: