Mar-13-2019, 12:14 PM
(This post was last modified: Mar-13-2019, 12:14 PM by AlekseyPython.)
Thanks to all!
It turned out that the error was that the events were not reusable.
It turned out that the error was that the events were not reusable.
import asyncio, time async def waiter(event, index_corrutine, start): print('start: ' + str(index_corrutine) + '\ttime=' + str(round(time.time()-start))) await event.wait() print('end: ' + str(index_corrutine) + '\ttime=' + str(round(time.time()-start))) async def main(): # Create an Event object. event = asyncio.Event() start = time.time() waiter_task1 = asyncio.create_task(waiter(event, 1, start)) await asyncio.sleep(3) event.set() waiter_task2 = asyncio.create_task(waiter(event, 2, start)) await asyncio.sleep(1) event.set() # Wait until the waiters of tasks is finished. await waiter_task1, waiter_task2 asyncio.run(main()) exit(1)
Output:start: 1 time=0
end: 1 time=3
start: 2 time=3
end: 2 time=3
That is, after the event is set, it stops doing something, but does not throw an exception. Therefore, it seems that everything works correctly.