Show More
@@ -18,6 +18,7 b' For more details, see the ipython-zmq design' | |||||
18 | from __future__ import print_function |
|
18 | from __future__ import print_function | |
19 |
|
19 | |||
20 | import bdb |
|
20 | import bdb | |
|
21 | import signal | |||
21 | import sys |
|
22 | import sys | |
22 | import time |
|
23 | import time | |
23 |
|
24 | |||
@@ -169,9 +170,34 b' class ZMQTerminalInteractiveShell(TerminalInteractiveShell):' | |||||
169 | """ Method to capture raw_input |
|
170 | """ Method to capture raw_input | |
170 | """ |
|
171 | """ | |
171 | msg_rep = self.km.stdin_channel.get_msg(timeout=timeout) |
|
172 | msg_rep = self.km.stdin_channel.get_msg(timeout=timeout) | |
172 | if self.session_id == msg_rep["parent_header"]["session"] : |
|
173 | # in case any iopub came while we were waiting: | |
173 | raw_data = raw_input(msg_rep["content"]["prompt"]) |
|
174 | self.handle_iopub() | |
174 | self.km.stdin_channel.input(raw_data) |
|
175 | if self.session_id == msg_rep["parent_header"]["session"]: | |
|
176 | # wrap SIGINT handler | |||
|
177 | real_handler = signal.getsignal(signal.SIGINT) | |||
|
178 | def double_int(sig,frame): | |||
|
179 | # call real handler (forwards sigint to kernel), | |||
|
180 | # then raise local interrupt, stopping local raw_input | |||
|
181 | real_handler(sig,frame) | |||
|
182 | raise KeyboardInterrupt | |||
|
183 | signal.signal(signal.SIGINT, double_int) | |||
|
184 | ||||
|
185 | try: | |||
|
186 | raw_data = raw_input(msg_rep["content"]["prompt"]) | |||
|
187 | except EOFError: | |||
|
188 | # turn EOFError into EOF character | |||
|
189 | raw_data = '\x04' | |||
|
190 | except KeyboardInterrupt: | |||
|
191 | sys.stdout.write('\n') | |||
|
192 | return | |||
|
193 | finally: | |||
|
194 | # restore SIGINT handler | |||
|
195 | signal.signal(signal.SIGINT, real_handler) | |||
|
196 | ||||
|
197 | # only send stdin reply if there *was not* another request | |||
|
198 | # or execution finished while we were reading. | |||
|
199 | if not (self.km.stdin_channel.msg_ready() or self.km.shell_channel.msg_ready()): | |||
|
200 | self.km.stdin_channel.input(raw_data) | |||
175 |
|
201 | |||
176 | def mainloop(self, display_banner=False): |
|
202 | def mainloop(self, display_banner=False): | |
177 | while True: |
|
203 | while True: |
@@ -469,6 +469,9 b' class Kernel(Configurable):' | |||||
469 | self.log.error("Got bad raw_input reply: ") |
|
469 | self.log.error("Got bad raw_input reply: ") | |
470 | self.log.error(str(Message(parent))) |
|
470 | self.log.error(str(Message(parent))) | |
471 | value = '' |
|
471 | value = '' | |
|
472 | if value == '\x04': | |||
|
473 | # EOF | |||
|
474 | raise EOFError | |||
472 | return value |
|
475 | return value | |
473 |
|
476 | |||
474 | def _complete(self, msg): |
|
477 | def _complete(self, msg): |
General Comments 0
You need to be logged in to leave comments.
Login now