Show More
@@ -140,7 +140,6 b' class ZMQTerminalIPythonApp(TerminalIPythonApp):' | |||||
140 | ipython_dir=self.ipython_dir, kernel_manager=self.kernel_manager) |
|
140 | ipython_dir=self.ipython_dir, kernel_manager=self.kernel_manager) | |
141 |
|
141 | |||
142 | def handle_sigint(self, *args): |
|
142 | def handle_sigint(self, *args): | |
143 | # FIXME: this doesn't work, the kernel just dies every time |
|
|||
144 | self.shell.write('KeyboardInterrupt\n') |
|
143 | self.shell.write('KeyboardInterrupt\n') | |
145 | self.kernel_manager.interrupt_kernel() |
|
144 | self.kernel_manager.interrupt_kernel() | |
146 |
|
145 |
@@ -185,7 +185,7 b' class ZMQTerminalInteractiveShell(TerminalInteractiveShell):' | |||||
185 |
|
185 | |||
186 | while not self.exit_now: |
|
186 | while not self.exit_now: | |
187 | if not self.km.is_alive: |
|
187 | if not self.km.is_alive: | |
188 | ans = self.raw_input("kernel died, restart (y/n)?") |
|
188 | ans = self.raw_input("kernel died, restart ([y]/n)?") | |
189 | if not ans.lower().startswith('n'): |
|
189 | if not ans.lower().startswith('n'): | |
190 | self.km.restart_kernel(True) |
|
190 | self.km.restart_kernel(True) | |
191 | else: |
|
191 | else: |
@@ -22,7 +22,9 b' import sys' | |||||
22 | import time |
|
22 | import time | |
23 | import traceback |
|
23 | import traceback | |
24 | import logging |
|
24 | import logging | |
25 |
|
25 | from signal import ( | ||
|
26 | signal, default_int_handler, SIGINT, SIG_IGN | |||
|
27 | ) | |||
26 | # System library imports. |
|
28 | # System library imports. | |
27 | import zmq |
|
29 | import zmq | |
28 |
|
30 | |||
@@ -168,6 +170,9 b' class Kernel(Configurable):' | |||||
168 | def start(self): |
|
170 | def start(self): | |
169 | """ Start the kernel main loop. |
|
171 | """ Start the kernel main loop. | |
170 | """ |
|
172 | """ | |
|
173 | # a KeyboardInterrupt (SIGINT) can occur on any python statement, so | |||
|
174 | # let's ignore (SIG_IGN) them until we're in a place to handle them properly | |||
|
175 | signal(SIGINT,SIG_IGN) | |||
171 | poller = zmq.Poller() |
|
176 | poller = zmq.Poller() | |
172 | poller.register(self.shell_socket, zmq.POLLIN) |
|
177 | poller.register(self.shell_socket, zmq.POLLIN) | |
173 | # loop while self.eventloop has not been overridden |
|
178 | # loop while self.eventloop has not been overridden | |
@@ -181,10 +186,15 b' class Kernel(Configurable):' | |||||
181 | # double nested try/except, to properly catch KeyboardInterrupt |
|
186 | # double nested try/except, to properly catch KeyboardInterrupt | |
182 | # due to pyzmq Issue #130 |
|
187 | # due to pyzmq Issue #130 | |
183 | try: |
|
188 | try: | |
|
189 | # restore raising of KeyboardInterrupt | |||
|
190 | signal(SIGINT, default_int_handler) | |||
184 | poller.poll(10*1000*self._poll_interval) |
|
191 | poller.poll(10*1000*self._poll_interval) | |
185 | self.do_one_iteration() |
|
192 | self.do_one_iteration() | |
186 | except: |
|
193 | except: | |
187 | raise |
|
194 | raise | |
|
195 | finally: | |||
|
196 | # prevent raising of KeyboardInterrupt | |||
|
197 | signal(SIGINT,SIG_IGN) | |||
188 | except KeyboardInterrupt: |
|
198 | except KeyboardInterrupt: | |
189 | # Ctrl-C shouldn't crash the kernel |
|
199 | # Ctrl-C shouldn't crash the kernel | |
190 | io.raw_print("KeyboardInterrupt caught in kernel") |
|
200 | io.raw_print("KeyboardInterrupt caught in kernel") |
General Comments 0
You need to be logged in to leave comments.
Login now