def run_async(metrics_list: list, addr: str, port: int,
              collector: Callable) -> None:
    """
    This function starts the async loop with the aio-prometheus server.
    :param metrics_list:
    :param addr:
    :param port:
    :param collector:
    :return: None
    """
    loop = asyncio.get_event_loop()
    svr = Service()
    try:
        loop.run_until_complete(
            server(svr, metrics_list, addr, port, collector))
    except KeyboardInterrupt:
        pass
    finally:
        loop.run_until_complete(svr.stop())
    loop.close()
Exemple #2
0
        raise Exception('Ooops')
    await asyncio.sleep(duration)


async def handle_requests():
    # Start up the server to expose the metrics.
    await svr.start(port=8000)
    # Generate some requests.
    while True:
        try:
            await handle_request(random.random())
        except:
            pass  # keep handling


if __name__ == '__main__':

    loop = asyncio.get_event_loop()

    svr = Service(loop=loop)
    svr.registry.register(REQUESTS)

    try:
        loop.run_until_complete(handle_requests())
    except KeyboardInterrupt:
        pass
    finally:
        loop.run_until_complete(svr.stop())
    loop.stop()
    loop.close()
        raise Exception("Ooops")
    await asyncio.sleep(duration)


async def handle_requests():
    # Start up the server to expose the metrics.
    await svr.start(port=8000)
    # Generate some requests.
    while True:
        try:
            await handle_request(random.random())
        except Exception:
            pass  # keep handling


if __name__ == "__main__":

    loop = asyncio.get_event_loop()

    svr = Service(loop=loop)
    svr.register(REQUESTS)

    try:
        loop.run_until_complete(handle_requests())
    except KeyboardInterrupt:
        pass
    finally:
        loop.run_until_complete(svr.stop())
    loop.stop()
    loop.close()