最简单的方法是仅使用通常的
Ctrl-C(SIGINT)中断它。
try: while True: do_something()except KeyboardInterrupt: pass
由于
Ctrl-C会引发原因
KeyboardInterrupt,因此只需将其捕获到循环之外并忽略它即可。

最简单的方法是仅使用通常的
Ctrl-C(SIGINT)中断它。
try: while True: do_something()except KeyboardInterrupt: pass
由于
Ctrl-C会引发原因
KeyboardInterrupt,因此只需将其捕获到循环之外并忽略它即可。