jupyter / jupyter_console

Jupyter Terminal Console
http://jupyter-console.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
250 stars 145 forks source link

Jupyter console is broken (run_sync expects coroutines) #277

Closed NeilGirdhar closed 1 year ago

NeilGirdhar commented 1 year ago

Jupyter console appears to be simply broken since any use of it triggers an assertion:

❯ jupyter --version
Selected Jupyter core packages...
IPython          : 8.9.0
ipykernel        : 6.21.1
ipywidgets       : 8.0.4
jupyter_client   : 8.0.2
jupyter_core     : 5.2.0
jupyter_server   : 2.2.1
jupyterlab       : not installed
nbclient         : 0.7.2
nbconvert        : 7.2.9
nbformat         : 5.7.3
notebook         : 6.5.2
qtconsole        : 5.4.0
traitlets        : 5.9.0
❯ jupyter console
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
Jupyter console 6.4.4

Python 3.11.1 (main, Jan  9 2023, 17:26:13) [GCC 11.3.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.9.0 -- An enhanced Interactive Python. Type '?' for help.

then I type "x" and press enter, which produces:

Unhandled exception in event loop:
  File "/home/neil/.pyenv/versions/3.11.1/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/neil/.pyenv/versions/3.11.1/lib/python3.11/site-packages/prompt_toolkit/input/vt100.py", line 173, in callback_wrapper
    callback()
  File "/home/neil/.pyenv/versions/3.11.1/lib/python3.11/site-packages/prompt_toolkit/application/application.py", line 707, in read_from_input
    self.key_processor.process_keys()
  File "/home/neil/.pyenv/versions/3.11.1/lib/python3.11/site-packages/prompt_toolkit/key_binding/key_processor.py", line 270, in process_keys
    self._process_coroutine.send(key_press)
  File "/home/neil/.pyenv/versions/3.11.1/lib/python3.11/site-packages/prompt_toolkit/key_binding/key_processor.py", line 185, in _process
    self._call_handler(matches[-1], key_sequence=buffer[:])
  File "/home/neil/.pyenv/versions/3.11.1/lib/python3.11/site-packages/prompt_toolkit/key_binding/key_processor.py", line 320, in _call_handler
    handler.call(event)
  File "/home/neil/.pyenv/versions/3.11.1/lib/python3.11/site-packages/prompt_toolkit/key_binding/key_bindings.py", line 124, in call
    result = self.handler(event)
             ^^^^^^^^^^^^^^^^^^^
  File "/home/neil/.pyenv/versions/3.11.1/lib/python3.11/site-packages/jupyter_console/ptshell.py", line 477, in _
    self.handle_iopub()
  File "/home/neil/.pyenv/versions/3.11.1/lib/python3.11/site-packages/jupyter_console/ptshell.py", line 854, in handle_iopub
    while run_sync(self.client.iopub_channel.msg_ready)():
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/neil/.pyenv/versions/3.11.1/lib/python3.11/site-packages/jupyter_core/utils/__init__.py", line 147, in run_sync
    raise AssertionError

Exception 
Press ENTER to continue...

Apparently, self.client.iopub_channel.msg_ready is not a coroutine, but run_sync expects it to be.

rpigott commented 1 year ago

I can reproduce this with python 3.10.9:

$ jupyter-console --kernel=python
Jupyter console 6.4.4

Python 3.10.9 (main, Dec 19 2022, 17:35:49) [GCC 12.2.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.9.0 -- An enhanced Interactive Python. Type '?' for help.

Unhandled exception in event loop:
  File "/usr/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/lib/python3.10/site-packages/prompt_toolkit/input/vt100.py", line 173, in callback_wrapper
    callback()
  File "/usr/lib/python3.10/site-packages/prompt_toolkit/application/application.py", line 707, in read_from_input
    self.key_processor.process_keys()
  File "/usr/lib/python3.10/site-packages/prompt_toolkit/key_binding/key_processor.py", line 270, in process_keys
    self._process_coroutine.send(key_press)
  File "/usr/lib/python3.10/site-packages/prompt_toolkit/key_binding/key_processor.py", line 185, in _process
    self._call_handler(matches[-1], key_sequence=buffer[:])
  File "/usr/lib/python3.10/site-packages/prompt_toolkit/key_binding/key_processor.py", line 320, in _call_handler
    handler.call(event)
  File "/usr/lib/python3.10/site-packages/prompt_toolkit/key_binding/key_bindings.py", line 124, in call
    result = self.handler(event)
  File "/usr/lib/python3.10/site-packages/jupyter_console/ptshell.py", line 477, in _
    self.handle_iopub()
  File "/usr/lib/python3.10/site-packages/jupyter_console/ptshell.py", line 854, in handle_iopub
    while run_sync(self.client.iopub_channel.msg_ready)():
  File "/usr/lib/python3.10/site-packages/jupyter_core/utils/__init__.py", line 147, in run_sync
    raise AssertionError

Exception 
Press ENTER to continue...
rpigott commented 1 year ago

Fixed by #276.

NeilGirdhar commented 1 year ago

Same problem with completions: Type from typing import then hit tab.

Unhandled exception in event loop:
  File "/home/neil/.cache/pypoetry/virtualenvs/tjax-DRMj3ydM-py3.11/lib/python3.11/site-packages/prompt_toolkit/buffer.py", line 1939, in new_coroutine
    await coroutine(*a, **kw)
  File "/home/neil/.cache/pypoetry/virtualenvs/tjax-DRMj3ydM-py3.11/lib/python3.11/site-packages/prompt_toolkit/eventloop/async_context_manager.py", line 79, in __aexit__
    await self.gen.athrow(typ, value, traceback)
  File "/home/neil/.cache/pypoetry/virtualenvs/tjax-DRMj3ydM-py3.11/lib/python3.11/site-packages/prompt_toolkit/eventloop/async_generator.py", line 42, in aclosing
    yield thing
  File "/home/neil/.cache/pypoetry/virtualenvs/tjax-DRMj3ydM-py3.11/lib/python3.11/site-packages/prompt_toolkit/buffer.py", line 1763, in async_completer
    async for completion in async_generator:
  File "/home/neil/.cache/pypoetry/virtualenvs/tjax-DRMj3ydM-py3.11/lib/python3.11/site-packages/prompt_toolkit/completion/base.py", line 326, in get_completions_async
    async for completion in completer.get_completions_async(
  File "/home/neil/.cache/pypoetry/virtualenvs/tjax-DRMj3ydM-py3.11/lib/python3.11/site-packages/prompt_toolkit/completion/base.py", line 202, in get_completions_async
    for item in self.get_completions(document, complete_event):
  File "/home/neil/.cache/pypoetry/virtualenvs/tjax-DRMj3ydM-py3.11/lib/python3.11/site-packages/jupyter_console/ptshell.py", line 174, in get_completions
    content = self.jup_completer.complete_request(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/neil/.cache/pypoetry/virtualenvs/tjax-DRMj3ydM-py3.11/lib/python3.11/site-packages/jupyter_console/completer.py", line 37, in complete_request
    msg = run_sync(self.client.shell_channel.get_msg)(timeout=self.timeout)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/neil/.cache/pypoetry/virtualenvs/tjax-DRMj3ydM-py3.11/lib/python3.11/site-packages/jupyter_core/utils/__init__.py", line 147, in run_sync
    raise AssertionError