##// END OF EJS Templates
qtconsole: fix race-cond, handle multiple exec...
Matthias BUSSONNIER -
Show More
@@ -138,6 +138,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
138 138 self._input_splitter = self._input_splitter_class(input_mode='cell')
139 139 self._kernel_manager = None
140 140 self._request_info = {}
141 self._request_info['execute'] = {};
141 142 self._callback_dict = {}
142 143
143 144 # Configure the ConsoleWidget.
@@ -199,7 +200,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
199 200 See parent class :meth:`execute` docstring for full details.
200 201 """
201 202 msg_id = self.kernel_manager.shell_channel.execute(source, hidden)
202 self._request_info['execute'] = self._ExecutionRequest(msg_id, 'user')
203 self._request_info['execute'][msg_id] = self._ExecutionRequest(msg_id, 'user')
203 204 self._hidden = hidden
204 205 if not hidden:
205 206 self.executing.emit(source)
@@ -343,7 +344,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
343 344 msg_id = self.kernel_manager.shell_channel.execute('',
344 345 silent=True, user_expressions={ local_uuid:expr })
345 346 self._callback_dict[local_uuid] = callback
346 self._request_info['execute'] = self._ExecutionRequest(msg_id, 'silent_exec_callback')
347 self._request_info['execute'][msg_id] = self._ExecutionRequest(msg_id, 'silent_exec_callback')
347 348
348 349 def _handle_exec_callback(self, msg):
349 350 """Execute `callback` corresonding to `msg` reply, after ``_silent_exec_callback``
@@ -373,12 +374,14 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
373 374 """ Handles replies for code execution.
374 375 """
375 376 self.log.debug("execute: %s", msg.get('content', ''))
376 info = self._request_info.get('execute')
377 info_list = self._request_info.get('execute')
378 msg_id = msg['parent_header']['msg_id']
379 if msg_id in info_list:
380 info = info_list[msg_id]
377 381 # unset reading flag, because if execute finished, raw_input can't
378 382 # still be pending.
379 383 self._reading = False
380 if info and info.id == msg['parent_header']['msg_id'] and \
381 info.kind == 'user' and not self._hidden:
384 if info and info.kind == 'user' and not self._hidden:
382 385 # Make sure that all output from the SUB channel has been processed
383 386 # before writing a new prompt.
384 387 self.kernel_manager.sub_channel.flush()
@@ -400,8 +403,8 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
400 403
401 404 self._show_interpreter_prompt_for_reply(msg)
402 405 self.executed.emit(msg)
403 elif info and info.id == msg['parent_header']['msg_id'] and \
404 info.kind == 'silent_exec_callback' and not self._hidden:
406 info_list.pop(msg_id)
407 elif info and info.kind == 'silent_exec_callback' and not self._hidden:
405 408 self._handle_exec_callback(msg)
406 409 else:
407 410 super(FrontendWidget, self)._handle_execute_reply(msg)
@@ -559,7 +562,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
559 562 """
560 563 if self._executing:
561 564 self._executing = False
562 self._request_info['execute'] = None
565 self._request_info['execute'] = {}
563 566 self._reading = False
564 567 self._highlighter.highlighting_on = False
565 568
@@ -211,18 +211,20 b' class HistoryConsoleWidget(ConsoleWidget):'
211 211 'hlen':'len(get_ipython().history_manager.input_hist_raw)',
212 212 }
213 213 )
214 self._request_info['execute'] = self._ExecutionRequest(msg_id, 'save_magic')
214 self._request_info['execute'][msg_id] = self._ExecutionRequest(msg_id, 'save_magic')
215 215
216 216 def _handle_execute_reply(self, msg):
217 217 """ Handles replies for code execution, here only session history length
218 218 """
219 info = self._request_info.get('execute')
220 if info and info.id == msg['parent_header']['msg_id'] and \
221 info.kind == 'save_magic' and not self._hidden:
222 content = msg['content']
223 status = content['status']
224 if status == 'ok':
225 self._max_session_history=(int(content['user_expressions']['hlen']))
219 info_list = self._request_info.get('execute')
220 msg_id = msg['parent_header']['msg_id']
221 if msg_id in info_list:
222 info = info_list.pop(msg_id)
223 if info.kind == 'save_magic' and not self._hidden:
224 content = msg['content']
225 status = content['status']
226 if status == 'ok':
227 self._max_session_history=(int(content['user_expressions']['hlen']))
226 228
227 229 def save_magic(self):
228 230 # update the session history length
@@ -165,11 +165,14 b' class IPythonWidget(FrontendWidget):'
165 165 def _handle_execute_reply(self, msg):
166 166 """ Reimplemented to support prompt requests.
167 167 """
168 info = self._request_info.get('execute')
169 if info and info.id == msg['parent_header']['msg_id']:
168 info_list = self._request_info.get('execute')
169 msg_id = msg['parent_header']['msg_id']
170 if msg_id in info_list:
171 info = info_list[msg_id]
170 172 if info.kind == 'prompt':
171 173 number = msg['content']['execution_count'] + 1
172 174 self._show_interpreter_prompt(number)
175 info_list.pop(msg_id)
173 176 else:
174 177 super(IPythonWidget, self)._handle_execute_reply(msg)
175 178
@@ -358,7 +361,7 b' class IPythonWidget(FrontendWidget):'
358 361 if number is None:
359 362 msg_id = self.kernel_manager.shell_channel.execute('', silent=True)
360 363 info = self._ExecutionRequest(msg_id, 'prompt')
361 self._request_info['execute'] = info
364 self._request_info['execute'][msg_id] = info
362 365 return
363 366
364 367 # Show a new prompt and save information about it so that it can be
@@ -629,6 +629,9 b' class MainWindow(QtGui.QMainWindow):'
629 629 self.pop = QtGui.QAction("&Update All Magic Menu ",
630 630 self, triggered=self.update_all_magic_menu)
631 631 self.add_menu_action(self.all_magic_menu, self.pop)
632 # we need to populate the 'Magic Menu' once the kernel has answer at
633 # least once let's do it immedialy, but it's assured to works
634 self.pop.trigger()
632 635
633 636 self.reset_action = QtGui.QAction("&Reset",
634 637 self,
@@ -452,9 +452,6 b' class IPythonQtConsoleApp(BaseIPythonApplication):'
452 452 self.window.add_tab_with_frontend(self.widget)
453 453 self.window.init_menu_bar()
454 454
455 # we need to populate the 'Magic Menu' once the kernel has answer at least once
456 self.kernel_manager.shell_channel.first_reply.connect(self.window.pop.trigger)
457
458 455 self.window.setWindowTitle('Python' if self.pure else 'IPython')
459 456
460 457 def init_colors(self):
General Comments 0
You need to be logged in to leave comments. Login now