44import os
55import sys
66from warnings import warn
7- from typing import Union as UnionType
7+ from typing import Union as UnionType , Optional
88
99from IPython .core .async_helpers import get_asyncio_loop
1010from 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
0 commit comments