Created
February 28, 2021 10:28
-
-
Save ansipunk/8d946149c7d607ee598dab3e4dc86407 to your computer and use it in GitHub Desktop.
Event loop soup
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 random | |
async def crumble(number: int) -> None: | |
print(f'Крошим залупу {number}...') | |
await asyncio.sleep(random.random()) | |
print(f'Залупа {number} покрошена.') | |
async def main() -> None: | |
print('Начинаем готовить суп!') | |
await asyncio.gather(*[ | |
asyncio.ensure_future(crumble(i)) for i in range(1, 8)]) | |
print('Суп готов.') | |
if __name__ == '__main__': | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment