Created
March 30, 2024 23:09
-
-
Save normanlmfung/3b24eea6735ee4c2f7c4ac623b91f256 to your computer and use it in GitHub Desktop.
python_syntax_asyncio_create_task
This file contains hidden or 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 greet(name): | |
await asyncio.sleep(1) | |
print(f"Hello, {name}!") | |
async def main(): | |
task1 = asyncio.create_task(greet("Alice")) | |
task2 = asyncio.create_task(greet("Bob")) | |
await asyncio.gather(task1, task2) | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment