Advertisement
Pandaaaa906

Untitled

Jun 21st, 2022
989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. import asyncio
  2.  
  3. from loguru import logger
  4.  
  5.  
  6. async def long_task(n: int):
  7.     cur_task = asyncio.current_task()
  8.     task_name = cur_task.get_name()
  9.     logger.info(f'{task_name} starting')
  10.     await asyncio.sleep(n)
  11.     logger.info(f'{task_name} finished')
  12.  
  13.  
  14. async def main():
  15.     nums = tuple(range(0, 8, 2))
  16.     logger.info('starting')
  17.     await asyncio.gather(*(long_task(n) for n in nums))
  18.     logger.info('finished')
  19.  
  20. if __name__ == '__main__':
  21.     asyncio.run(main())
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement