'Send Ctrl + C to asyncio Task

So I have two tasks running until complete in my event loop. I want to handle KeyboardInterrupt when running those Tasks and send the same signal to the Tasks in the event loop when receiving it.

 loop = asyncio.get_event_loop()
    try:
        loop.run_until_complete(asyncio.gather(
            task_1(),
            task_2()
        ))
    except KeyboardInterrupt:
        pass
        # Here I want to send sigterm to the tasks in event loop

Is there any way to do this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source