Skip to content

Instantly share code, notes, and snippets.

@gmolveau
Last active March 26, 2021 09:34
Show Gist options
  • Save gmolveau/e4c86f0990e9bbaff2372d529e7da042 to your computer and use it in GitHub Desktop.
Save gmolveau/e4c86f0990e9bbaff2372d529e7da042 to your computer and use it in GitHub Desktop.
examples async/await asyncio concurrency python3
import asyncio
async def c1():
print("c1 begin")
await asyncio.sleep(1)
print("c1 end")
return
async def c2():
print("c2 begin")
await asyncio.sleep(3)
print("c2 end")
return
async def main():
tasks = []
tasks.append(asyncio.create_task(c1()))
tasks.append(asyncio.create_task(c2()))
for t in tasks:
await t
if __name__ == "__main__":
asyncio.run(main())
import asyncio
async def answer():
print(42)
async def main():
await answer()
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment