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

Unable to start jupyter console: "RuntimeError: asyncio.run() cannot be called from a running event loop" #298

Closed rpigott closed 10 months ago

rpigott commented 11 months ago

I'm not able to start jupyter console. Unfortunately, I use it too infrequently to know precisely when it started failing. On startup, I get the following python traceback, which is the same regardless of the kernel chosen:

$ jupyter console --kernel=julia-1.9 
Starting kernel event loops.
Jupyter console 6.6.3

Julia: A fresh approach to technical computing.Traceback (most recent call last):
  File "/usr/bin/jupyter-console", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/lib/python3.11/site-packages/jupyter_core/application.py", line 307, in launch_instance
    loop.run_until_complete(coro)
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/jupyter_core/application.py", line 294, in _async_launch_instance
    app.start()
  File "/usr/lib/python3.11/site-packages/jupyter_console/app.py", line 148, in start
    self.shell.mainloop()
  File "/usr/lib/python3.11/site-packages/jupyter_console/ptshell.py", line 676, in mainloop
    asyncio.run(self._main_task())
  File "/usr/lib/python3.11/asyncio/runners.py", line 186, in run
    raise RuntimeError(
RuntimeError: asyncio.run() cannot be called from a running event loop
sys:1: RuntimeWarning: coroutine 'ZMQTerminalInteractiveShell._main_task' was never awaited

I'm using Arch Linux, and the following packages:

$ pacman -Q python jupyter-console
python 3.11.6-1
jupyter-console 6.6.3-2
$ jupyter --version
Selected Jupyter core packages...
IPython          : 8.19.0
ipykernel        : 6.28.0
ipywidgets       : not installed
jupyter_client   : 8.6.0
jupyter_core     : 5.6.0
jupyter_server   : 2.12.1
jupyterlab       : 4.0.9
nbclient         : 0.9.0
nbconvert        : 7.13.1
nbformat         : 5.9.2
notebook         : 7.0.6
qtconsole        : not installed
traitlets        : 5.14.0
VelocityREST commented 11 months ago

I got the exact same issue, I use Arch as well. EDIT: I just have recalled that I have updated jupyter yesterday or today morning. That change must have introduced this bug.

natsukium commented 11 months ago

I guess this change in jupyter-core causes this problem. For now, the workaround is to set jupyter_core == 5.5.1.

VelocityREST commented 11 months ago

jupyter_core == 5.5.1

Do you mean to downgrade the package manually using the package manger? Because I searched for an option to use a specific jupyter_core version and I couldn't find a away

natsukium commented 11 months ago

Do you mean to downgrade the package manually using the package manger?

Yes

ccordoba12 commented 11 months ago

This is a the problem with Arch: it's maintainers sometimes update packages too quickly and then you end up with issues like this.

Since that version was yanked on PyPI, please report that in the Arch bug tracker so they revert to 5.5.1.

rpigott commented 10 months ago

This appears to be resolved by jupyter_core 5.7.1. Thanks everyone.