Show More
@@ -1,5 +1,6 | |||
|
1 | 1 | """IPython terminal interface using prompt_toolkit""" |
|
2 | 2 | |
|
3 | import asyncio | |
|
3 | 4 | import os |
|
4 | 5 | import sys |
|
5 | 6 | import warnings |
@@ -309,6 +310,7 class TerminalInteractiveShell(InteractiveShell): | |||
|
309 | 310 | |
|
310 | 311 | editing_mode = getattr(EditingMode, self.editing_mode.upper()) |
|
311 | 312 | |
|
313 | self.pt_loop = asyncio.new_event_loop() | |
|
312 | 314 | self.pt_app = PromptSession( |
|
313 | 315 | editing_mode=editing_mode, |
|
314 | 316 | key_bindings=key_bindings, |
@@ -448,10 +450,21 class TerminalInteractiveShell(InteractiveShell): | |||
|
448 | 450 | default = '' |
|
449 | 451 | |
|
450 | 452 | with patch_stdout(raw=True): |
|
453 | # In order to make sure that asyncio code written in the | |
|
454 | # interactive shell doesn't interfere with the prompt, we run the | |
|
455 | # prompt in a different event loop. | |
|
456 | # If we don't do this, people could spawn coroutine with a | |
|
457 | # while/true inside which will freeze the prompt. | |
|
458 | ||
|
459 | old_loop = asyncio.get_event_loop() | |
|
460 | asyncio.set_event_loop(self.pt_loop) | |
|
461 | try: | |
|
451 | 462 | text = self.pt_app.prompt( |
|
452 | 463 | default=default, |
|
453 | # pre_run=self.pre_prompt,# reset_current_buffer=True, | |
|
454 | 464 | **self._extra_prompt_options()) |
|
465 | finally: | |
|
466 | # Restore the original event loop. | |
|
467 | asyncio.set_event_loop(old_loop) | |
|
455 | 468 | return text |
|
456 | 469 | |
|
457 | 470 | def enable_win_unicode_console(self): |
@@ -568,11 +581,11 class TerminalInteractiveShell(InteractiveShell): | |||
|
568 | 581 | # this inputhook. |
|
569 | 582 | if PTK3: |
|
570 | 583 | if self._inputhook: |
|
571 |
from prompt_toolkit.eventloop import |
|
|
572 | set_eventloop_with_inputhook(self._inputhook) | |
|
584 | from prompt_toolkit.eventloop import new_eventloop_with_inputhook | |
|
585 | self.pt_loop = new_eventloop_with_inputhook(self._inputhook) | |
|
573 | 586 | else: |
|
574 | 587 | import asyncio |
|
575 |
|
|
|
588 | self.pt_loop = asyncio.new_event_loop() | |
|
576 | 589 | |
|
577 | 590 | # Run !system commands directly, not through pipes, so terminal programs |
|
578 | 591 | # work correctly. |
General Comments 0
You need to be logged in to leave comments.
Login now