Exemple #1
0
def main():
    logger.info("Starting asyncstib")

    loop = asyncio.get_event_loop()
    loop.run_until_complete(db.connect_async(loop=loop))
    logger.debug("Postgres connection ok")

    logger.debug("Gathering network info")
    network = Network()
    # we only need line numbers and we don't want Noctis
    lines = [line.id for line in network.lines if 'N' not in str(line.id)]
    routes = [(line, 1) for line in lines] + [(line, 2) for line in lines]
    # routes = routes[:2]

    semaphore = asyncio.Semaphore(CONCURRENCY)

    logger.info("Adding %i tasks (lines)", len(routes))
    for i, (line, way) in enumerate(routes):
        sleep = i * PERIOD / len(routes)
        asyncio.async(route_loop(sleep, line, way, semaphore))

    logger.info("Starting main loop")
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        logger.warning('KeyboardInterrupt')
Exemple #2
0
def main():
    logger.info("Starting asyncstib")

    loop = asyncio.get_event_loop()
    loop.run_until_complete(db.connect_async(loop=loop))
    logger.debug("Postgres connection ok")

    lines = LINES

    routes = [(line, 1) for line in lines] + [(line, 2) for line in lines]

    semaphore = asyncio.Semaphore(CONCURRENCY)

    logger.info("Adding %i tasks (lines)", len(routes))
    for i, (line, way) in enumerate(routes):
        sleep = i * PERIOD / len(routes)
        asyncio. async (route_loop(sleep, line, way, semaphore))

    logger.info("Starting main loop")
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        logger.warning('KeyboardInterrupt')
def main():
    logger.info("Starting asyncstib")

    loop = asyncio.get_event_loop()
    loop.run_until_complete(db.connect_async(loop=loop))
    logger.debug("Postgres connection ok")


    lines = LINES

    routes = [(line, 1) for line in lines] + [(line, 2) for line in lines]

    semaphore = asyncio.Semaphore(CONCURRENCY)

    logger.info("Adding %i tasks (lines)", len(routes))
    for i, (line, way) in enumerate(routes):
        sleep = i * PERIOD / len(routes)
        asyncio.async(route_loop(sleep, line, way, semaphore))

    logger.info("Starting main loop")
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        logger.warning('KeyboardInterrupt')