Untitled
unknown
python
2 years ago
772 B
12
Indexable
Never
import asyncio from concurrent.futures import ThreadPoolExecutor async def sleep1(): print('start sleep1') await asyncio.sleep(5) print('end sleep1') async def sleep2(): print('start sleep2') await asyncio.sleep(1) print('end sleep2') async def handler(): print('in handler') print(id(asyncio.get_running_loop())) task1 = asyncio.create_task(sleep1()) task2 = asyncio.create_task(sleep2()) await asyncio.gather(task1, task2) async def main(): print('in main') with ThreadPoolExecutor() as executor: print('in ThreadPoolExecutor') print(1) executor.submit(asyncio.run, handler()) print(2) executor.submit(asyncio.run, handler()) print('main end') asyncio.run(main())