Skip to content

Instantly share code, notes, and snippets.

@dputtick
Created June 23, 2017 04:33
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 dputtick/c76039b11f86b1a58c458321a5bbac20 to your computer and use it in GitHub Desktop.
Save dputtick/c76039b11f86b1a58c458321a5bbac20 to your computer and use it in GitHub Desktop.
Asyncio counting
import asyncio
async def count(name, number):
n = 1
while n < number + 1:
print(name, ':', n)
n += 1
await asyncio.sleep(1)
return n
async def run():
coros = []
for name in range(10):
coros.append(count(name, 10))
numbers = await asyncio.wait(coros)
return numbers
def main():
loop = asyncio.get_event_loop()
numbers = loop.run_until_complete(run())
print(numbers)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment