I have some asyncio tasks and I need to pause all of them. This is my part of code:
import asyncio import random async def workers1(): while True: k = random.randint(100, 200) await asyncio.sleep(k) await my_print(k) async def workers2(): while True: k = random.randint(100, 200) await asyncio.sleep(k) await my_print(k) async def my_print(k): print(k) if k == 122: >>>>>>> suspend all of workers while k != 155: k = await repair() await asyncio.sleep(1) r>>>>>> resume all of workers async def main(): tasks = [asyncio.create_task(workers1()), asyncio.create_task(workers2()) ] [await x for x in tasks] if __name__ == '__main__': asyncio.run(main()) How can I suspend all of workers in my code when trouble happens in a function my_print and after repair in my_print resume all of tasks?
I will be glad if you give an example. I have been seen this link. But that's not what I need.
>>>>>>>" and "r>>>>>>" mean? The syntax highlighter is not fond of it.