尝试编写一个在代码中按CTRL+ 号退出的代码时, C实现时会遇到问题,因为大多数在线帮助都涉及信号和其他可能与要求无关的内容。可以跳过此部分并提供解决方案
import signal
import time
def sigint_handler(signum, frame):
print 'Stop pressing the CTRL+C!'
signal.signal(signal.SIGINT, sigint_handler)
Run Code Online (Sandbox Code Playgroud)
目的:
按ctrl+ c应该只是退出程序