Kernel event loop is robust against random SIGINT. #472

Merged
merged 2 commits into from May 26, 2011

Projects

None yet

2 participants

@takluyver
Member

Kernel event loop catches KeyboardInterrupt (i.e. SIGINT, Ctrl-C) and carries on running. This was prompted by trouble we were having with the zmqterminal frontend (#433). This doesn't prevent us from interrupting execution of user code.

@fperez fperez commented on an outdated diff May 26, 2011
IPython/zmq/ipkernel.py
@@ -167,8 +167,12 @@ class Kernel(Configurable):
""" Start the kernel main loop.
"""
while True:
- time.sleep(self._poll_interval)
- self.do_one_iteration()
+ try:
+ time.sleep(self._poll_interval)
+ self.do_one_iteration()
+ except KeyboardInterrupt:
+ # Ctrl-C shouldn't crash the kernel
+ continue
@fperez
fperez May 26, 2011 Member

I'd put a print statement here so that people know the kernel did something. If not, they will rapid-fire ctrl-C enough times to slip through, as eventually one of the signals will occur in the except block, where it won't get caught.

The print can be as simple as

KeyboardInterrupt

like we do at the console.

Otherwise looks good, once that fix is made, merge away.

@takluyver takluyver merged commit 5cd1ae1 into ipython:master May 26, 2011
@takluyver
Member

Changed according to @fperez's suggestion, rebased, and merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment