Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- from loguru import logger
- async def long_task(n: int):
- cur_task = asyncio.current_task()
- task_name = cur_task.get_name()
- logger.info(f'{task_name} starting')
- await asyncio.sleep(n)
- logger.info(f'{task_name} finished')
- async def main():
- nums = tuple(range(0, 8, 2))
- logger.info('starting')
- await asyncio.gather(*(long_task(n) for n in nums))
- logger.info('finished')
- if __name__ == '__main__':
- asyncio.run(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement