当按下Ctrl+C时,我的while循环不会退出。它似乎忽略了我的KeyboardInterrupt异常。循环部分如下:
while True:
try:
if subprocess_cnt <= max_subprocess:
try:
notifier.process_events()
if notifier.check_events():
notifier.read_events()
except KeyboardInterrupt:
notifier.stop()
break
else:
pass
except (KeyboardInterrupt, SystemExit):
print '\nkeyboardinterrupt found!'
print '\n...Program Stopped Manually!'
raise
我不确定问题出在哪里,但是我的终端从来没有打印出我在异常中设置的两个打印警告。有人能帮我解决这个问题吗?
except KeyboardInterrupt
捕获了异常。如果你不重新抛出它,它将对第二个except (KeyboardInterrupt, SystemExit)
不可见。 - eumiroexcept KeyboardInterrupt:
中添加raise KeyboardInterrupt()
来重新引发 KeyboardInterrupt 异常,但我仍然遇到了相同的问题。 - sadmicrowave