#!/usr/bin/env python
import signal
import sys
import os
def signal_handler(signal, frame):
print('You pressed Ctrl+C!')
# signal.signal(signal.SIGINT, signal_handler)
print('Press Ctrl+C')
# os.system('pause')
class SIGINT_handler():
def __init__(self):
self.SIGINT = False
def signal_handler(self, signal, frame):
print('You pressed Ctrl+C!')
self.SIGINT = True
handler = SIGINT_handler()
signal.signal(signal.SIGINT, handler.signal_handler)
os.system('pause')
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240825082459112-376424429.jpg)