1import asyncio
2import signal
3
4def on_trap(loop,signum):
5 print(f"shlian on_trap:{signum}")
6 print("loop is stopping...")
7 loop.stop()
8 print("loop stopped")
9
10if __name__=="__main__":
11
12 loop=asyncio.get_event_loop()
13 loop.add_signal_handler(signal.SIGINT,on_trap,loop,signal.SIGINT)
14 loop.run_forever()
15