當按下Ctrl + C時,我的while循環不會退出。它似乎忽略了我的KeyboardInterrupt異常。環路部分看起來是這樣的:python退出無限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
同樣,我不知道是什麼問題,但我從來沒有終端甚至打印兩個打印提醒我在我的異常。有人可以幫我解決這個問題嗎?
您的第一個'除了KeyboardInterrupt'捕獲異常。如果你不重新提高它,第二個'except(KeyboardInterrupt,SystemExit)'不可見。 – eumiro 2011-12-27 14:23:59
@eumiro - 我註釋掉了第一個KeyboardInterrupt,並用'pass'替換了異常的內容,但我仍然遇到同樣的問題。 Ctrl + C被忽略(ps aux顯示進程仍然在運行) – sadmicrowave 2011-12-27 14:30:42
@eumiro我也試圖通過在第一個'除KeyboardInterrupt:'之外添加'raise KeyboardInterrupt()'來重新引發KeyboardInterrupt異常。我仍然遇到同樣的問題。 – sadmicrowave 2011-12-27 14:50:49