File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed
src/prompt_toolkit/application Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -943,13 +943,22 @@ def run_in_thread() -> None:
943
943
raise exception
944
944
return result
945
945
946
- return asyncio .run (
947
- self .run_async (
948
- pre_run = pre_run ,
949
- set_exception_handler = set_exception_handler ,
950
- handle_sigint = handle_sigint ,
951
- )
946
+ coro = self .run_async (
947
+ pre_run = pre_run ,
948
+ set_exception_handler = set_exception_handler ,
949
+ handle_sigint = handle_sigint ,
952
950
)
951
+ try :
952
+ # See whether a loop was installed already. If so, use that. That's
953
+ # required for the input hooks to work, they are installed using
954
+ # `set_event_loop`.
955
+ loop = asyncio .get_event_loop ()
956
+ except RuntimeError :
957
+ # No loop installed. Run like usual.
958
+ return asyncio .run (coro )
959
+ else :
960
+ # Use existing loop.
961
+ return loop .run_until_complete (coro )
953
962
954
963
def _handle_exception (
955
964
self , loop : AbstractEventLoop , context : dict [str , Any ]
You can’t perform that action at this time.
0 commit comments