跳转至

信号

优雅地退出。

while True:
    pass
python ./while_true.py
Traceback (most recent call last):
  File "C:\Users\ws\Documents\Dev\projects\zendesk_search\search\while_true.py", line 2, in <module>
    pass
KeyboardInterrupt
import signal
import sys


def sigint_handler(signals, frame_type):
    print('Bye.')
    sys.exit()


signal.signal(signal.SIGINT, sigint_handler)

while True:
    pass
python ./while_true.py
Bye.