Skip to content

Instantly share code, notes, and snippets.

@TobCap
Created August 27, 2019 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TobCap/20a2801bee7598673618e62a4909dda0 to your computer and use it in GitHub Desktop.
Save TobCap/20a2801bee7598673618e62a4909dda0 to your computer and use it in GitHub Desktop.
python async await example
import asyncio
from time import time
async def slow_a():
print("a start")
await asyncio.sleep(2.5)
print("a end")
async def slow_b():
print("b start")
await asyncio.sleep(2.0)
print("b end")
async def main():
start = time()
print("start main")
t1 = asyncio.create_task(slow_a())
t2 = asyncio.create_task(slow_b())
await t1
await t2
print("end main")
print(time() - start)
if __name__ == '__main__':
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment