diff options
author | robot-contrib <robot-contrib@yandex-team.com> | 2023-09-30 10:27:28 +0300 |
---|---|---|
committer | robot-contrib <robot-contrib@yandex-team.com> | 2023-09-30 10:47:10 +0300 |
commit | 5a6373c9d09bbfb7094f9992a4531477bb97829e (patch) | |
tree | ebea8fd55fee858876743312cdf789a1f01487b5 /contrib/python/ipython/py3/IPython/terminal | |
parent | 15f3c7493474de25a6b23296878bb8f49470d2e6 (diff) | |
download | ydb-5a6373c9d09bbfb7094f9992a4531477bb97829e.tar.gz |
Update contrib/python/ipython/py3 to 8.15.0
Diffstat (limited to 'contrib/python/ipython/py3/IPython/terminal')
3 files changed, 22 insertions, 13 deletions
diff --git a/contrib/python/ipython/py3/IPython/terminal/debugger.py b/contrib/python/ipython/py3/IPython/terminal/debugger.py index 7a0623c847..19ed3c7f60 100644 --- a/contrib/python/ipython/py3/IPython/terminal/debugger.py +++ b/contrib/python/ipython/py3/IPython/terminal/debugger.py @@ -10,6 +10,7 @@ from . import embed from pathlib import Path from pygments.token import Token +from prompt_toolkit.application import create_app_session from prompt_toolkit.shortcuts.prompt import PromptSession from prompt_toolkit.enums import EditingMode from prompt_toolkit.formatted_text import PygmentsTokens @@ -95,6 +96,17 @@ class TerminalPdb(Pdb): self.pt_loop = asyncio.new_event_loop() self.pt_app = PromptSession(**options) + def _prompt(self): + """ + In case other prompt_toolkit apps have to run in parallel to this one (e.g. in madbg), + create_app_session must be used to prevent mixing up between them. According to the prompt_toolkit docs: + + > If you need multiple applications running at the same time, you have to create a separate + > `AppSession` using a `with create_app_session():` block. + """ + with create_app_session(): + return self.pt_app.prompt() + def cmdloop(self, intro=None): """Repeatedly issue a prompt, accept input, parse an initial prefix off the received input, and dispatch to action methods, passing them @@ -128,9 +140,7 @@ class TerminalPdb(Pdb): # Run the prompt in a different thread. if not _use_simple_prompt: try: - line = self.thread_executor.submit( - self.pt_app.prompt - ).result() + line = self.thread_executor.submit(self._prompt).result() except EOFError: line = "EOF" else: diff --git a/contrib/python/ipython/py3/IPython/terminal/interactiveshell.py b/contrib/python/ipython/py3/IPython/terminal/interactiveshell.py index 75cf25ea66..37e0b86981 100644 --- a/contrib/python/ipython/py3/IPython/terminal/interactiveshell.py +++ b/contrib/python/ipython/py3/IPython/terminal/interactiveshell.py @@ -914,6 +914,15 @@ class TerminalInteractiveShell(InteractiveShell): active_eventloop = None def enable_gui(self, gui=None): + if self.simple_prompt is True and gui is not None: + print( + f'Cannot install event loop hook for "{gui}" when running with `--simple-prompt`.' + ) + print( + "NOTE: Tk is supported natively; use Tk apps and Tk backends with `--simple-prompt`." + ) + return + if self._inputhook is None and gui is None: print("No event loop hook running.") return diff --git a/contrib/python/ipython/py3/IPython/terminal/pt_inputhooks/osx.py b/contrib/python/ipython/py3/IPython/terminal/pt_inputhooks/osx.py index 2754820efc..9b8a0cd98e 100644 --- a/contrib/python/ipython/py3/IPython/terminal/pt_inputhooks/osx.py +++ b/contrib/python/ipython/py3/IPython/terminal/pt_inputhooks/osx.py @@ -116,11 +116,8 @@ def _wake(NSApp): msg(NSApp, n('postEvent:atStart:'), void_p(event), True) -_triggered = Event() - def _input_callback(fdref, flags, info): """Callback to fire when there's input to be read""" - _triggered.set() CFFileDescriptorInvalidate(fdref) CFRelease(fdref) NSApp = _NSApp() @@ -134,7 +131,6 @@ _c_input_callback = _c_callback_func_type(_input_callback) def _stop_on_read(fd): """Register callback to stop eventloop when there's data on fd""" - _triggered.clear() fdref = CFFileDescriptorCreate(None, fd, False, _c_input_callback, None) CFFileDescriptorEnableCallBacks(fdref, kCFFileDescriptorReadCallBack) source = CFFileDescriptorCreateRunLoopSource(None, fdref, 0) @@ -149,9 +145,3 @@ def inputhook(context): _stop_on_read(context.fileno()) objc.objc_msgSend.argtypes = [void_p, void_p] msg(NSApp, n('run')) - if not _triggered.is_set(): - # app closed without firing callback, - # probably due to last window being closed. - # Run the loop manually in this case, - # since there may be events still to process (#9734) - CoreFoundation.CFRunLoopRun() |