Skip to content

Instantly share code, notes, and snippets.

@ansipunk
Created February 28, 2021 10:28
Show Gist options
  • Save ansipunk/8d946149c7d607ee598dab3e4dc86407 to your computer and use it in GitHub Desktop.
Save ansipunk/8d946149c7d607ee598dab3e4dc86407 to your computer and use it in GitHub Desktop.
Event loop soup
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