def run(self): # FIXME: parent pid is not supported on windows. Maybe we should # find a way for the task to check if the parent is alive in another # way in this case? if not _is_windows: os.setpgrp() self._ppid = os.getppid() t = threading.Thread(target=self._check_parent_running) t.daemon = True t.start() else: from stoqserver.main import setup_stoq, setup_logging from stoqserver.sentry import setup_excepthook # Do this as soon as possible so we can log any early traceback setup_excepthook() # Allow .pyd files to be imported from egg files from zipextimporter import ZipExtensionImporter sys.path_hooks.append(ZipExtensionImporter) sys.path_importer_cache.clear() cacerts_path = os.path.join(_root, 'cacert.pem') requests.utils.DEFAULT_CA_BUNDLE_PATH = cacerts_path requests.adapters.DEFAULT_CA_BUNDLE_PATH = cacerts_path setup_stoq() setup_logging() if isinstance(self.func, tuple): # Windows plugin_name, task_name = self.func manager = get_plugin_manager() plugin = manager.get_plugin(plugin_name) for task in plugin.get_server_tasks(): if task.name == task_name: break else: raise AssertionError func = task.start else: func = self.func # Workaround a python issue where multiprocessing/threading will not # use the modified sys.excepthook: https://bugs.python.org/issue1230540 try: func(*self._func_args, **self._func_kwargs) except Exception: sys.excepthook(*sys.exc_info()) self._error_queue.put(self.name)
def run(self): # FIXME: parent pid is not supported on windows. Maybe we should # find a way for the task to check if the parent is alive in another # way in this case? if not _is_windows: os.setpgrp() self._ppid = os.getppid() t = threading.Thread(target=self._check_parent_running) t.daemon = True t.start() else: from stoqserver.main import (setup_stoq, setup_logging, setup_excepthook) # Do this as soon as possible so we can log any early traceback setup_excepthook() # Allow .pyd files to be imported from egg files from zipextimporter import ZipExtensionImporter sys.path_hooks.append(ZipExtensionImporter) sys.path_importer_cache.clear() cacerts_path = os.path.join(_root, 'cacert.pem') requests.utils.DEFAULT_CA_BUNDLE_PATH = cacerts_path requests.adapters.DEFAULT_CA_BUNDLE_PATH = cacerts_path setup_stoq() setup_logging() if isinstance(self.func, tuple): # Windows plugin_name, task_name = self.func manager = get_plugin_manager() plugin = manager.get_plugin(plugin_name) for task in plugin.get_server_tasks(): if task.name == task_name: break else: raise AssertionError func = task.start else: func = self.func # Workaround a python issue where multiprocessing/threading will not # use the modified sys.excepthook: https://bugs.python.org/issue1230540 try: func(*self._func_args, **self._func_kwargs) except Exception: sys.excepthook(*sys.exc_info()) self._error_queue.put(self.name)
# """ run with: gunicorn stoqserver.gunicorn -w 4 -b localhost:6971 -k gevent """ from stoqserver import activate_virtualenv activate_virtualenv() # This needs to be done ASAP, before any other imports. from gevent import monkey from psycogreen.gevent import patch_psycopg monkey.patch_all() patch_psycopg() import stoq from stoqserver import app from stoqserver.main import setup_stoq, setup_logging import sys # sys.argv comes with the arguments passed to gunicorn, but stoq will not work well with those. sys.argv = [] setup_stoq(register_station=True, name='stoqflask', version=stoq.version) setup_logging(app_name='stoq-flask') application = app.bootstrap_app(debug=False, multiclient=True)