Example #1
0
    def run(self):
        try:
            self.loop = loop = asyncio.new_event_loop()
            asyncio.set_event_loop(loop)
            loop.set_debug(True)

            event_registry = EventRegistry()
            app = make_app(event_registry, self.shared_state)
            self.server = app.listen(address="127.0.0.1", port=self.port)
            # self.shared_state.set_server(self.server)

            asyncio.ensure_future(self.wait_for_stop())
            self.start_event.set()
            loop.run_forever()
        finally:
            self.loop.stop()
Example #2
0
async def server_port(unused_tcp_port_factory, shared_data):
    """
    start a LiberTEM API server on a unused port
    """
    loop = asyncio.get_event_loop()
    loop.set_debug(True)
    port = unused_tcp_port_factory()
    event_registry = EventRegistry()
    app = make_app(event_registry, shared_data)
    print("starting server at port {}".format(port))
    server = app.listen(address="127.0.0.1", port=port)
    yield port
    print("stopping server at port {}".format(port))
    server.stop()
    await server.close_all_connections()
    if shared_data.have_executor():
        await shared_data.get_executor().close()
Example #3
0
    def run(self):
        try:
            adjust_event_loop_policy()
            self.loop = loop = asyncio.new_event_loop()
            asyncio.set_event_loop(loop)
            loop.set_debug(True)

            event_registry = EventRegistry()
            app = make_app(event_registry, self.shared_state, self.token)
            self.server = tornado.httpserver.HTTPServer(app)
            self.server.listen(address="127.0.0.1", port=self.port)
            # self.shared_state.set_server(self.server)

            asyncio.ensure_future(self.wait_for_stop())
            self.start_event.set()
            loop.run_forever()
        finally:
            self.loop.stop()