|
29 | 29 | from zmq.eventloop.zmqstream import ZMQStream |
30 | 30 |
|
31 | 31 | from traitlets.config.configurable import SingletonConfigurable |
32 | | -from IPython.core.error import StdinNotImplementedError |
| 32 | +from IPython.core.error import StdinNotImplementedError, UsageError |
33 | 33 | from ipython_genutils import py3compat |
34 | 34 | from ipython_genutils.py3compat import unicode_type, string_types |
35 | 35 | from ipykernel.jsonutil import json_clean |
@@ -191,6 +191,26 @@ def handle_msg(msg): |
191 | 191 | self._stdin_msg = msg |
192 | 192 |
|
193 | 193 | self.stdin_stream.on_recv(handle_msg, copy=False) |
| 194 | + # Should the eventloop be run while waiting for input |
| 195 | + self._input_eventloop = False |
| 196 | + |
| 197 | + def input_eventloop(self, active): |
| 198 | + """ |
| 199 | + Activates and desactivates the eventloop while waiting for input. |
| 200 | +
|
| 201 | + active is "True" or "False" (Strings as it is used as a magic) |
| 202 | +
|
| 203 | + This allows eg. matplotlib plots to be used while debugging. |
| 204 | +
|
| 205 | + This should not be active while debugging a gui application that |
| 206 | + uses the same eventloop as the events will be processed. |
| 207 | + """ |
| 208 | + if active == "True": |
| 209 | + self._input_eventloop = True |
| 210 | + elif active == "False": |
| 211 | + self._input_eventloop = False |
| 212 | + else: |
| 213 | + raise UsageError('Please use "True" or "False"') |
194 | 214 |
|
195 | 215 | @gen.coroutine |
196 | 216 | def dispatch_control(self, msg): |
@@ -943,7 +963,7 @@ def _input_request_loop_step(self): |
943 | 963 | else: |
944 | 964 | is_main_thread = isinstance(threading.current_thread(), |
945 | 965 | threading._MainThread) |
946 | | - if is_main_thread and self.eventloop: |
| 966 | + if is_main_thread and self.eventloop and self._input_eventloop: |
947 | 967 | self.eventloop(self) |
948 | 968 | return self._stdin_msg |
949 | 969 | else: |
|
0 commit comments