Show More
@@ -631,7 +631,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
631 |
|
631 | |||
632 | editing_mode = getattr(EditingMode, self.editing_mode.upper()) |
|
632 | editing_mode = getattr(EditingMode, self.editing_mode.upper()) | |
633 |
|
633 | |||
634 | self.pt_loop = asyncio.new_event_loop() |
|
634 | self._use_asyncio_inputhook = False | |
635 | self.pt_app = PromptSession( |
|
635 | self.pt_app = PromptSession( | |
636 | auto_suggest=self.auto_suggest, |
|
636 | auto_suggest=self.auto_suggest, | |
637 | editing_mode=editing_mode, |
|
637 | editing_mode=editing_mode, | |
@@ -798,24 +798,23 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
798 | # If we don't do this, people could spawn coroutine with a |
|
798 | # If we don't do this, people could spawn coroutine with a | |
799 | # while/true inside which will freeze the prompt. |
|
799 | # while/true inside which will freeze the prompt. | |
800 |
|
800 | |||
801 | policy = asyncio.get_event_loop_policy() |
|
|||
802 | old_loop = get_asyncio_loop() |
|
|||
803 |
|
||||
804 | # FIXME: prompt_toolkit is using the deprecated `asyncio.get_event_loop` |
|
|||
805 | # to get the current event loop. |
|
|||
806 | # This will probably be replaced by an attribute or input argument, |
|
|||
807 | # at which point we can stop calling the soon-to-be-deprecated `set_event_loop` here. |
|
|||
808 | if old_loop is not self.pt_loop: |
|
|||
809 | policy.set_event_loop(self.pt_loop) |
|
|||
810 | try: |
|
|||
811 |
|
|
801 | with patch_stdout(raw=True): | |
|
802 | if self._use_asyncio_inputhook: | |||
|
803 | # When we integrate the asyncio event loop, run the UI in the | |||
|
804 | # same event loop as the rest of the code. don't use an actual | |||
|
805 | # input hook. (Asyncio is not made for nesting event loops.) | |||
|
806 | asyncio_loop = get_asyncio_loop() | |||
|
807 | text = asyncio_loop.run_until_complete( | |||
|
808 | self.pt_app.prompt_async( | |||
|
809 | default=default, **self._extra_prompt_options() | |||
|
810 | ) | |||
|
811 | ) | |||
|
812 | else: | |||
812 | text = self.pt_app.prompt( |
|
813 | text = self.pt_app.prompt( | |
813 | default=default, |
|
814 | default=default, | |
814 | **self._extra_prompt_options()) |
|
815 | inputhook=self._inputhook, | |
815 | finally: |
|
816 | **self._extra_prompt_options(), | |
816 | # Restore the original event loop. |
|
817 | ) | |
817 | if old_loop is not None and old_loop is not self.pt_loop: |
|
|||
818 | policy.set_event_loop(old_loop) |
|
|||
819 |
|
818 | |||
820 | return text |
|
819 | return text | |
821 |
|
820 | |||
@@ -950,29 +949,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
950 | else: |
|
949 | else: | |
951 | self.active_eventloop = self._inputhook = None |
|
950 | self.active_eventloop = self._inputhook = None | |
952 |
|
951 | |||
953 | # For prompt_toolkit 3.0. We have to create an asyncio event loop with |
|
952 | self._use_asyncio_inputhook = gui == "asyncio" | |
954 | # this inputhook. |
|
|||
955 | if PTK3: |
|
|||
956 | import asyncio |
|
|||
957 | from prompt_toolkit.eventloop import new_eventloop_with_inputhook |
|
|||
958 |
|
||||
959 | if gui == 'asyncio': |
|
|||
960 | # When we integrate the asyncio event loop, run the UI in the |
|
|||
961 | # same event loop as the rest of the code. don't use an actual |
|
|||
962 | # input hook. (Asyncio is not made for nesting event loops.) |
|
|||
963 | self.pt_loop = get_asyncio_loop() |
|
|||
964 | print("Installed asyncio event loop hook.") |
|
|||
965 |
|
||||
966 | elif self._inputhook: |
|
|||
967 | # If an inputhook was set, create a new asyncio event loop with |
|
|||
968 | # this inputhook for the prompt. |
|
|||
969 | self.pt_loop = new_eventloop_with_inputhook(self._inputhook) |
|
|||
970 | print(f"Installed {self.active_eventloop} event loop hook.") |
|
|||
971 | else: |
|
|||
972 | # When there's no inputhook, run the prompt in a separate |
|
|||
973 | # asyncio event loop. |
|
|||
974 | self.pt_loop = asyncio.new_event_loop() |
|
|||
975 | print("GUI event loop hook disabled.") |
|
|||
976 |
|
953 | |||
977 | # Run !system commands directly, not through pipes, so terminal programs |
|
954 | # Run !system commands directly, not through pipes, so terminal programs | |
978 | # work correctly. |
|
955 | # work correctly. |
General Comments 0
You need to be logged in to leave comments.
Login now