示例#1
0
    def _start_server(self,
                      pipelines=dict(),
                      topic=None,
                      host=None,
                      allow_stop=True):
        pipeline_driver = FakePipelineDriver()
        for key, value in pipelines.items():
            pipeline_driver.add_pipeline(value, name=key)

        server = ProcessServer(host or 'test.host',
                               pipeline_driver=pipeline_driver,
                               topic=topic,
                               allow_stop=allow_stop)

        thread = threading.Thread(target=server.start)
        thread.daemon = True
        thread.server = server
        thread.start()

        return thread
示例#2
0
文件: __init__.py 项目: benhe119/gate
class Server(Daemon):

    def __init__(self, host):
        self.host = host
        self.rpc_server = ProcessServer(self.host, self.pipelines)

    def start(self):
        """Starts the rpc server."""
        self.rpc_server.start()

    def wait(self):
        """Waits for rpc server to end."""
        self.rpc_server.wait()

    def stop(self):
        """Stops the rpc server"""
        self.rpc_server.stop()

    def run_forever(self, *args, **kwargs):
        """Run the process continuously."""
        self.start()
        try:
            self.wait()
        except:
            self.stop()
            raise
        self.stop()

    def run_once(self, *args, **kwargs):
        """Run the process one pass."""
        self.start()
        try:
            self.wait()
        except:
            self.stop()
            raise
        self.stop()
示例#3
0
文件: __init__.py 项目: benhe119/gate
 def __init__(self, host):
     self.host = host
     self.rpc_server = ProcessServer(self.host, self.pipelines)