コード例 #1
0
async def test_cancel(executor: aiomisc.ThreadPoolExecutor, loop, timer):
    assert executor

    sleep = aiomisc.threaded(time.sleep)

    with timer(1, dispersion=2):
        tasks = [loop.create_task(sleep(1)) for _ in range(1000)]

        await asyncio.sleep(1)

        for task in tasks:
            task.cancel()

        executor.shutdown(wait=True)
コード例 #2
0
def main():
    entrypoint.PRE_START.connect(on_start)
    entrypoint.POST_STOP.connect(on_stop)

    with entrypoint(*services) as loop:
        loop.set_default_executor(ThreadPoolExecutor(4))
        loop.run_forever()
コード例 #3
0
async def main():
    conf = Config()

    logging.basicConfig(level=logging.DEBUG)
    logging.config.dictConfig(conf.DEFAULT_LOGGING)
    logger = logging.getLogger(__name__)

    db = ExtendedDBManager(init_db(conf))
    db.database.create_tables([Article], safe=True)

    executor = ThreadPoolExecutor(max_workers=10)
    loop.set_default_executor(executor)

    DATA_FOR_MATPLOTLIB = {}

    await truncate(db=db)
    await vacuum(db=db)
    await drop_index(db=db)

    for mode in ["noindex", 'index']:
        await truncate(db=db)
        await vacuum(db=db)
        if mode == 'index':
            await create_index(db=db)
        else:
            await drop_index(db=db)

        for i in range(1, 81):
            await buck_create_new(db=db, epoch_count=i, count=10**6, mode=mode)
            row1 = await db.get(Article.select().limit(1))
            row2 = await db.get(Article.select().order_by(
                Article.created_date.desc()).limit(1))

            if mode == 'noindex':
                arv_time__noindex1 = await call_avr_time(db=db, text=row1.name)
                arv_time__noindex2 = await call_avr_time(db=db, text=row2.name)
                arv_time__noindex = max(arv_time__noindex1, arv_time__noindex2)

                logger.info(f"Time NoIndex={arv_time__noindex}")
                DATA_FOR_MATPLOTLIB[str(i)] = {"noindex": arv_time__noindex}
            else:
                arv_time__index1 = await call_avr_time(db=db, text=row1.name)
                arv_time__index2 = await call_avr_time(db=db, text=row2.name)
                arv_time__index = max(arv_time__index1, arv_time__index2)

                logger.info(f"Time Index={arv_time__index}")
                DATA_FOR_MATPLOTLIB[str(i)].update({"index": arv_time__index})

            logger.info(f"")
            now_count = await db.count(Article.select())
            logger.info(f"Row in db count = {now_count}")
            logger.info(f"==  ==  " * 15)
            logger.info(f"==  ==  " * 15)

    FileReader.write_data(DATA_FOR_MATPLOTLIB)
    logger.info(f"Exit")
コード例 #4
0
async def test_future_already_done(executor: aiomisc.ThreadPoolExecutor):
    futures = []

    for _ in range(10):
        futures.append(executor.submit(time.sleep, 0.1))

    for future in futures:
        future.set_exception(asyncio.CancelledError())

    await asyncio.gather(*futures, return_exceptions=True)
コード例 #5
0
def setup_app(conf):
    app = web.Application(client_max_size=conf.MAX_BODY_SIZE,
                          logger=log.access_logger,
                          middlewares=[])
    app["conf"] = conf

    app.on_startup.append(on_startup)
    app.on_cleanup.append(on_cleanup)
    app.on_shutdown.append(on_shutdown)

    app.router.add_routes(routes)  # setup views and routes

    loop = asyncio.get_event_loop()

    executor = ThreadPoolExecutor(max_workers=10)
    app["executor"] = executor

    loop.set_default_executor(executor)

    return app
コード例 #6
0
                logger.info(f"Time Index={arv_time__index}")
                DATA_FOR_MATPLOTLIB[str(i)].update({"index": arv_time__index})

            logger.info(f"")
            now_count = await db.count(Article.select())
            logger.info(f"Row in db count = {now_count}")
            logger.info(f"==  ==  " * 15)
            logger.info(f"==  ==  " * 15)

    FileReader.write_data(DATA_FOR_MATPLOTLIB)
    logger.info(f"Exit")


if __name__ == '__main__':
    print(
        '= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ='
    )
    print(
        '= = = = = = = = = = = = = = = = = S T A R T   H W 7 = = = = = = = = = = = = = = = = = ='
    )
    print(
        '= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ='
    )

    loop = asyncio.get_event_loop()
    executor = ThreadPoolExecutor(max_workers=10)

    loop.set_default_executor(executor)

    run(main(), stop_on_unhandled_errors=True, use_uvloop=True)