Instantly share code, notes, and snippets.

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