Created
February 4, 2021 14:54
-
-
Save agronholm/2e8ba9f772a6dcf6170d956a8a95510c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from concurrent.futures import as_completed | |
from anyio import start_blocking_portal, sleep | |
async def long_running_task(index): | |
await sleep(1) | |
print(f'Task {index} running...') | |
await sleep(index) | |
return f'Task {index} return value' | |
with start_blocking_portal() as portal: | |
futures = [portal.spawn_task(long_running_task, i) for i in range(1, 5)] | |
for future in as_completed(futures): | |
print(future.result()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment