Skip to content

Instantly share code, notes, and snippets.

@dputtick dputtick/count.py
Created Jun 23, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.