Created
December 28, 2018 10:43
-
-
Save zmonoid/e32182b0b308c2025202af5b37315e38 to your computer and use it in GitHub Desktop.
Asyncio Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
# Borrowed from http://curio.readthedocs.org/en/latest/tutorial.html. | |
async def countdown(number, n): | |
while n > 0: | |
print('T-minus', n, '({})'.format(number)) | |
yield from asyncio.sleep(1) | |
n -= 1 | |
loop = asyncio.get_event_loop() | |
tasks = [ | |
asyncio.ensure_future(countdown("A", 2)), | |
asyncio.ensure_future(countdown("B", 3))] | |
loop.run_until_complete(asyncio.wait(tasks)) | |
loop.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment