コード例 #1
0
ファイル: single.py プロジェクト: ndparker/wtf
    def run(self):
        """
        Pool runner

        :See: `wtf.opi.worker.WorkerPoolInterface`
        """
        model, prerun, self.prerun = self.model, self.prerun, None
        impl = _impl.factory(model.config, model.opts, model.args)
        app = _app.factory(model.config, model.opts, model.args)
        try:
            accept, handle, flags = self.sock.accept, impl.handle, Flags()
            if prerun is not None:
                prerun()

            while True:
                try:
                    handle(accept(), app.call, flags)
                except (SystemExit, KeyboardInterrupt, _opi.OPIDone):
                    raise
                except:
                    print >> _sys.stderr, \
                        "Exception caught in single worker:\n" + ''.join(
                            _traceback.format_exception(*_sys.exc_info())
                        )
        finally:
            app.shutdown()
コード例 #2
0
ファイル: init.py プロジェクト: ndparker/wtf
def managed_app(configfile):
    """
    Create a managed application

    :Parameters:
      `configfile` : ``str``
        Config file name

    :Return: Application factory
    :Rtype: callable
    """
    from wtf import app as _app

    return _app.factory(config(configfile), None, None)
コード例 #3
0
ファイル: threaded.py プロジェクト: ndparker/wtf
    def run(self):
        """
        Pool runner

        :See: `wtf.opi.worker.WorkerPoolInterface`
        """
        # pylint: disable = R0912

        oldpid, self._pid = self._pid, None
        prerun, self.prerun = self.prerun, None
        parent_cleanup, self.parent_cleanup = self.parent_cleanup, None
        self._pid = _os.fork()
        if self._pid == 0: # child
            try:
                try:
                    if self._usergroup:
                        _osutil.change_identity(*self._usergroup)
                    _signal.signal(_signal.SIGINT, _signal.SIG_IGN)
                    _signal.signal(_signal.SIGHUP, _signal.SIG_IGN)
                    if self.child_cleanup is not None:
                        self.child_cleanup()

                    model = self.model
                    config, opts, args = model.config, model.opts, model.args
                    reload_checker = _reload.Autoreload(config, opts, args)
                    impl = _impl.factory(config, opts, args)
                    app = _app.factory(config, opts, args)

                    try:
                        pool = ThreadPool(
                            self, reload_checker, impl, app.call
                        )
                        if prerun is not None:
                            prerun()
                        pool.run()
                    finally:
                        app.shutdown()
                except SystemExit, e:
                    _os._exit(e.code or 0) # pylint: disable = W0212
                except:
                    _traceback.print_exc()
                    _os._exit(1) # pylint: disable = W0212
            finally:
コード例 #4
0
ファイル: init.py プロジェクト: wontfix-org/wtf
def managed_app(configfile):
    """ Create a managed application """
    from wtf import app as _app
    return _app.factory(config(configfile), None, None)