This paste expires on 2023-04-15 12:55:12.928909. Repaste, or download this paste. . Pasted through web.

import time
import functools
import concurrent.futures
import asyncio
def slow_task(i):
    print(f'running task: {i}')
    time.sleep(i)
    return i
async def main():
    loop = asyncio.get_event_loop()
    aws = []
    with concurrent.futures.ThreadPoolExecutor() as executor:
        for i in range(5):
            aws.append(loop.run_in_executor(executor, functools.partial(slow_task, i)))
    res = await asyncio.gather(*aws)
    print(res)
asyncio.run(main())
Filename: None. Size: 500b. View raw, , hex, or download this file.