Skip to content

Instantly share code, notes, and snippets.

@dputtick dputtick/

Created Jun 23, 2017
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())
if __name__ == '__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.