Navigation Menu

Skip to content

Commit

Permalink
ignore KeyboardInterrupt until we can handle it
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanov committed Oct 12, 2011
1 parent 9bb377b commit 026157b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 0 additions & 1 deletion IPython/frontend/zmqterminal/app.py
Expand Up @@ -140,7 +140,6 @@ def init_shell(self):
ipython_dir=self.ipython_dir, kernel_manager=self.kernel_manager) ipython_dir=self.ipython_dir, kernel_manager=self.kernel_manager)


def handle_sigint(self, *args): def handle_sigint(self, *args):
# FIXME: this doesn't work, the kernel just dies every time
self.shell.write('KeyboardInterrupt\n') self.shell.write('KeyboardInterrupt\n')
self.kernel_manager.interrupt_kernel() self.kernel_manager.interrupt_kernel()


Expand Down
2 changes: 1 addition & 1 deletion IPython/frontend/zmqterminal/interactiveshell.py
Expand Up @@ -185,7 +185,7 @@ def interact(self, display_banner=None):


while not self.exit_now: while not self.exit_now:
if not self.km.is_alive: if not self.km.is_alive:
ans = self.raw_input("kernel died, restart (y/n)?") ans = self.raw_input("kernel died, restart ([y]/n)?")
if not ans.lower().startswith('n'): if not ans.lower().startswith('n'):
self.km.restart_kernel(True) self.km.restart_kernel(True)
else: else:
Expand Down
11 changes: 11 additions & 0 deletions IPython/zmq/ipkernel.py
Expand Up @@ -22,6 +22,9 @@
import time import time
import traceback import traceback
import logging import logging
from signal import (
signal, default_int_handler, SIGINT, SIG_IGN
)
# System library imports. # System library imports.
import zmq import zmq


Expand Down Expand Up @@ -161,6 +164,9 @@ def do_one_iteration(self):
def start(self): def start(self):
""" Start the kernel main loop. """ Start the kernel main loop.
""" """
# a KeyboardInterrupt (SIGINT) can occur on any python statement, so
# let's ignore (SIG_IGN) them until we're in a place to handle them properly
signal(SIGINT,SIG_IGN)
poller = zmq.Poller() poller = zmq.Poller()
poller.register(self.shell_socket, zmq.POLLIN) poller.register(self.shell_socket, zmq.POLLIN)
while True: while True:
Expand All @@ -173,10 +179,15 @@ def start(self):
# double nested try/except, to properly catch KeyboardInterrupt # double nested try/except, to properly catch KeyboardInterrupt
# due to pyzmq Issue #130 # due to pyzmq Issue #130
try: try:
# restore raising of KeyboardInterrupt
signal(SIGINT, default_int_handler)
poller.poll(10*1000*self._poll_interval) poller.poll(10*1000*self._poll_interval)
self.do_one_iteration() self.do_one_iteration()
except: except:
raise raise
finally:
# prevent raising of KeyboardInterrupt
signal(SIGINT,SIG_IGN)
except KeyboardInterrupt: except KeyboardInterrupt:
# Ctrl-C shouldn't crash the kernel # Ctrl-C shouldn't crash the kernel
io.raw_print("KeyboardInterrupt caught in kernel") io.raw_print("KeyboardInterrupt caught in kernel")
Expand Down

0 comments on commit 026157b

Please sign in to comment.