Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3df4946

Browse files
authored
ENH: Don't show message when enable the current eventloop. (#14168)
Should take care of #14006, at least partially.
2 parents 3b47371 + cf63863 commit 3df4946

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

IPython/terminal/interactiveshell.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
import sys
66
from warnings import warn
7-
from typing import Union as UnionType
7+
from typing import Union as UnionType, Optional
88

99
from IPython.core.async_helpers import get_asyncio_loop
1010
from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
@@ -912,8 +912,9 @@ def inputhook(self, context):
912912
if self._inputhook is not None:
913913
self._inputhook(context)
914914

915-
active_eventloop = None
916-
def enable_gui(self, gui=None):
915+
active_eventloop: Optional[str] = None
916+
917+
def enable_gui(self, gui: Optional[str] = None) -> None:
917918
if self.simple_prompt is True and gui is not None:
918919
print(
919920
f'Cannot install event loop hook for "{gui}" when running with `--simple-prompt`.'
@@ -928,8 +929,15 @@ def enable_gui(self, gui=None):
928929
return
929930

930931
if self._inputhook is not None and gui is not None:
931-
print(
932-
f"Shell is already running a gui event loop for {self.active_eventloop}. "
932+
newev, newinhook = get_inputhook_name_and_func(gui)
933+
if self._inputhook == newinhook:
934+
# same inputhook, do nothing
935+
self.log.info(
936+
f"Shell is already running the {self.active_eventloop} eventloop. Doing nothing"
937+
)
938+
return
939+
self.log.warning(
940+
f"Shell is already running a different gui event loop for {self.active_eventloop}. "
933941
"Call with no arguments to disable the current loop."
934942
)
935943
return

IPython/terminal/pt_inputhooks/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import importlib
22
import os
3+
from typing import Tuple, Callable
34

45
aliases = {
56
'qt4': 'qt',
@@ -119,7 +120,7 @@ def set_qt_api(gui):
119120
return qt_env2gui[QT_API]
120121

121122

122-
def get_inputhook_name_and_func(gui):
123+
def get_inputhook_name_and_func(gui: str) -> Tuple[str, Callable]:
123124
if gui in registered:
124125
return gui, registered[gui]
125126

0 commit comments

Comments
 (0)