Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save normanlmfung/3b24eea6735ee4c2f7c4ac623b91f256 to your computer and use it in GitHub Desktop.
Save normanlmfung/3b24eea6735ee4c2f7c4ac623b91f256 to your computer and use it in GitHub Desktop.
python_syntax_asyncio_create_task
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