add_signal_handler

import asyncio
import signal

def on_trap(loop,signum):
    print(f"shlian on_trap:{signum}")
    print("loop is stopping...")
    loop.stop()
    print("loop stopped")

if __name__=="__main__":

    loop=asyncio.get_event_loop()
    loop.add_signal_handler(signal.SIGINT,on_trap,loop,signal.SIGINT)
    loop.run_forever()
shlian