예제 #1
0
    def __init__(self, app, root_dir, debug=False,
                 sub_cache_dir=None, run_sse_check=None):
        self.app = app
        self.root_dir = root_dir
        self.debug = debug
        self.sub_cache_dir = sub_cache_dir
        self.run_sse_check = run_sse_check
        self._proc_loop = None
        self._out_dir = os.path.join(root_dir, CACHE_DIR, 'server')
        if sub_cache_dir:
            self._out_dir = os.path.join(sub_cache_dir, 'server')
        self._handlers = {
                'debug_info': self._getDebugInfo,
                'werkzeug_shutdown': self._shutdownWerkzeug,
                'pipeline_status': self._startSSEProvider}

        if not self.run_sse_check or self.run_sse_check():
            # When using a server with code reloading, some implementations
            # use process forking and we end up going here twice. We only want
            # to start the pipeline loop in the inner process most of the
            # time so we let the implementation tell us if this is OK.
            from piecrust.serving.procloop import ProcessingLoop
            self._proc_loop = ProcessingLoop(root_dir, self._out_dir,
                                             sub_cache_dir=sub_cache_dir,
                                             debug=debug)
            self._proc_loop.start()
예제 #2
0
    def getWsgiApp(self):
        # Bake all the assets so we know what we have, and so we can serve
        # them to the client. We need a temp app for this.
        app = PieCrust(root_dir=self.root_dir, debug=self.debug)
        app._useSubCacheDir(self.sub_cache_dir)
        self._out_dir = os.path.join(app.sub_cache_dir, 'server')
        self._page_record = ServeRecord()

        if not self.run_sse_check or self.run_sse_check():
            # When using a server with code reloading, some implementations
            # use process forking and we end up going here twice. We only want
            # to start the pipeline loop in the inner process most of the
            # time so we let the implementation tell us if this is OK.
            from piecrust.processing.base import ProcessorPipeline
            from piecrust.serving.procloop import ProcessingLoop
            pipeline = ProcessorPipeline(app, self._out_dir)
            self._proc_loop = ProcessingLoop(pipeline)
            self._proc_loop.start()

        # Run the WSGI app.
        wsgi_wrapper = WsgiServerWrapper(self)
        return wsgi_wrapper