Created
December 10, 2017 19:04
-
-
Save amitnabarro/967d444e915abbedddb071e71054d277 to your computer and use it in GitHub Desktop.
Wait for stuff, concurrent
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 | |
import time | |
async def wait_for_stuff(): | |
start = time.time() | |
futures = [] | |
for i in range(0, 5): | |
futures.append(asyncio.sleep(1)) | |
await asyncio.wait(futures) | |
print('Time elapsed: %d seconds' % int(time.time() - start)) | |
try: | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(wait_for_stuff()) | |
finally: | |
loop.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment