Show More
@@ -1,5 +1,6 | |||||
1 | """IPython terminal interface using prompt_toolkit""" |
|
1 | """IPython terminal interface using prompt_toolkit""" | |
2 |
|
2 | |||
|
3 | import asyncio | |||
3 | import os |
|
4 | import os | |
4 | import sys |
|
5 | import sys | |
5 | import warnings |
|
6 | import warnings | |
@@ -309,6 +310,7 class TerminalInteractiveShell(InteractiveShell): | |||||
309 |
|
310 | |||
310 | editing_mode = getattr(EditingMode, self.editing_mode.upper()) |
|
311 | editing_mode = getattr(EditingMode, self.editing_mode.upper()) | |
311 |
|
312 | |||
|
313 | self.pt_loop = asyncio.new_event_loop() | |||
312 | self.pt_app = PromptSession( |
|
314 | self.pt_app = PromptSession( | |
313 | editing_mode=editing_mode, |
|
315 | editing_mode=editing_mode, | |
314 | key_bindings=key_bindings, |
|
316 | key_bindings=key_bindings, | |
@@ -448,10 +450,21 class TerminalInteractiveShell(InteractiveShell): | |||||
448 | default = '' |
|
450 | default = '' | |
449 |
|
451 | |||
450 | with patch_stdout(raw=True): |
|
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 | text = self.pt_app.prompt( |
|
462 | text = self.pt_app.prompt( | |
452 | default=default, |
|
463 | default=default, | |
453 | # pre_run=self.pre_prompt,# reset_current_buffer=True, |
|
|||
454 | **self._extra_prompt_options()) |
|
464 | **self._extra_prompt_options()) | |
|
465 | finally: | |||
|
466 | # Restore the original event loop. | |||
|
467 | asyncio.set_event_loop(old_loop) | |||
455 | return text |
|
468 | return text | |
456 |
|
469 | |||
457 | def enable_win_unicode_console(self): |
|
470 | def enable_win_unicode_console(self): | |
@@ -568,11 +581,11 class TerminalInteractiveShell(InteractiveShell): | |||||
568 | # this inputhook. |
|
581 | # this inputhook. | |
569 | if PTK3: |
|
582 | if PTK3: | |
570 | if self._inputhook: |
|
583 | if self._inputhook: | |
571 |
from prompt_toolkit.eventloop import |
|
584 | from prompt_toolkit.eventloop import new_eventloop_with_inputhook | |
572 | set_eventloop_with_inputhook(self._inputhook) |
|
585 | self.pt_loop = new_eventloop_with_inputhook(self._inputhook) | |
573 | else: |
|
586 | else: | |
574 | import asyncio |
|
587 | import asyncio | |
575 |
|
|
588 | self.pt_loop = asyncio.new_event_loop() | |
576 |
|
589 | |||
577 | # Run !system commands directly, not through pipes, so terminal programs |
|
590 | # Run !system commands directly, not through pipes, so terminal programs | |
578 | # work correctly. |
|
591 | # work correctly. |
@@ -190,7 +190,7 install_requires = [ | |||||
190 | 'decorator', |
|
190 | 'decorator', | |
191 | 'pickleshare', |
|
191 | 'pickleshare', | |
192 | 'traitlets>=4.2', |
|
192 | 'traitlets>=4.2', | |
193 | 'prompt_toolkit>=2.0.0,<3.1.0', |
|
193 | 'prompt_toolkit>=2.0.0,<3.1.0,!=3.0.0,!=3.0.1', | |
194 | 'pygments', |
|
194 | 'pygments', | |
195 | 'backcall', |
|
195 | 'backcall', | |
196 | ] |
|
196 | ] |
General Comments 0
You need to be logged in to leave comments.
Login now