Skip to content

Instantly share code, notes, and snippets.

@Glyphack
Last active April 25, 2019 11:48
Show Gist options
  • Save Glyphack/90eae68e9006344ce0e851a4fc1e4db0 to your computer and use it in GitHub Desktop.
Save Glyphack/90eae68e9006344ce0e851a4fc1e4db0 to your computer and use it in GitHub Desktop.
Implementing sorting with async.sleep
import asyncio
import time
import random
async def task(i):
await asyncio.sleep(i* 0.01)
print(i)
async def main():
a = [random.randint(0, 100) for _ in range(0, 100)]
coroutines = list()
for i in a:
coroutines.append(task(i))
await asyncio.gather(*coroutines)
start = time.time()
asyncio.run(main())
print(f"program took {time.time() - start} to finish")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment