async def test_simple(event_loop, timer): sleep = threaded(time.sleep) with timer(1): await asyncio.gather( sleep(1), sleep(1), sleep(1), sleep(1), )
async def test_threaded(executor: ThreadPoolExecutor, timer): assert executor sleep = threaded(time.sleep) with timer(1): await asyncio.gather( sleep(1), sleep(1), sleep(1), sleep(1), sleep(1), )
async def test_cancel(executor: ThreadPoolExecutor, event_loop, timer): assert executor sleep = threaded(time.sleep) with timer(1, dispersion=2): tasks = [event_loop.create_task(sleep(1)) for _ in range(1000)] await asyncio.sleep(1) for task in tasks: task.cancel() executor.shutdown(wait=True)
class AsyncMemoryHandler(logging.handlers.MemoryHandler): flush_async = threaded(logging.handlers.MemoryHandler.flush)