Created
December 23, 2021 13:40
-
-
Save gdamjan/826a35d5624c12e16b064e83d2d75a2e to your computer and use it in GitHub Desktop.
futures are lazy, tasks are eager (in async python)
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
import asyncio | |
async def test(s, n): | |
print(f' {s} started') | |
await asyncio.sleep(n) | |
print(f' {s} ends') | |
async def main(): | |
f = test('future', 1) | |
t = asyncio.create_task(test('task', 1)) | |
print('lets wait a bit in main') | |
await asyncio.sleep(3) | |
print('are we done?') | |
await asyncio.gather(f, t) | |
print('we are!') | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment