Notebook: RuntimeError: This event loop is already running

Created on 7 Aug 2020  路  6Comments  路  Source: jupyter/notebook

Hi.

There is no problem in running jupyter notebook, home page, directories etc. are coming. But when the kernel is started, the following errors occur.

C:\Users\dell>jupyter notebook
[I 16:16:56.674 NotebookApp] JupyterLab extension loaded from c:\python37\lib\site-packages\jupyterlab
[I 16:16:56.674 NotebookApp] JupyterLab application directory is c:\python37\share\jupyter\lab
[I 16:16:57.194 NotebookApp] Serving notebooks from local directory: C:\Users\dell
[I 16:16:57.194 NotebookApp] Jupyter Notebook 6.1.1 is running at:
[I 16:16:57.194 NotebookApp] http://localhost:8888/?token=fc849ad54c3c20c8916f31d55e622bc8c72b7f9ff8f7dd4a
[I 16:16:57.194 NotebookApp]  or http://127.0.0.1:8888/?token=fc849ad54c3c20c8916f31d55e622bc8c72b7f9ff8f7dd4a
[I 16:16:57.194 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 16:16:57.254 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///C:/Users/dell/AppData/Roaming/jupyter/runtime/nbserver-3900-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=fc849ad54c3c20c8916f31d55e622bc8c72b7f9ff8f7dd4a
     or http://127.0.0.1:8888/?token=fc849ad54c3c20c8916f31d55e622bc8c72b7f9ff8f7dd4a
[I 16:17:07.165 NotebookApp] Creating new notebook in
[I 16:17:10.415 NotebookApp] Kernel started: cc500446-cf7d-4c96-9952-30211013ac14, name: python3
ERROR:tornado.general:Uncaught exception in ZMQStream callback
Traceback (most recent call last):
  File "c:\python37\lib\site-packages\zmq\eventloop\zmqstream.py", line 438, in _run_callback
    callback(*args, **kwargs)
  File "c:\python37\lib\site-packages\ipykernel\kernelbase.py", line 283, in dispatcher
    return self.dispatch_shell(stream, msg)
  File "c:\python37\lib\site-packages\ipykernel\kernelbase.py", line 233, in dispatch_shell
    self.pre_handler_hook()
  File "c:\python37\lib\site-packages\ipykernel\kernelbase.py", line 248, in pre_handler_hook
    self.saved_sigint_handler = signal(SIGINT, default_int_handler)
  File "c:\python37\lib\signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread
ERROR:tornado.general:Uncaught exception in zmqstream callback
Traceback (most recent call last):
  File "c:\python37\lib\site-packages\zmq\eventloop\zmqstream.py", line 456, in _handle_events
    self._handle_recv()
  File "c:\python37\lib\site-packages\zmq\eventloop\zmqstream.py", line 486, in _handle_recv
    self._run_callback(callback, msg)
  File "c:\python37\lib\site-packages\zmq\eventloop\zmqstream.py", line 438, in _run_callback
    callback(*args, **kwargs)
  File "c:\python37\lib\site-packages\ipykernel\kernelbase.py", line 283, in dispatcher
    return self.dispatch_shell(stream, msg)
  File "c:\python37\lib\site-packages\ipykernel\kernelbase.py", line 233, in dispatch_shell
    self.pre_handler_hook()
  File "c:\python37\lib\site-packages\ipykernel\kernelbase.py", line 248, in pre_handler_hook
    self.saved_sigint_handler = signal(SIGINT, default_int_handler)
  File "c:\python37\lib\signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread
ERROR:tornado.application:Exception in callback functools.partial(<function ZMQStream._update_handler.<locals>.<lambda> at 0x000000000529CE58>)
Traceback (most recent call last):
  File "c:\python37\lib\site-packages\tornado\ioloop.py", line 743, in _run_callback
    ret = callback()
  File "c:\python37\lib\site-packages\zmq\eventloop\zmqstream.py", line 542, in <lambda>
    self.io_loop.add_callback(lambda : self._handle_events(self.socket, 0))
  File "c:\python37\lib\site-packages\zmq\eventloop\zmqstream.py", line 456, in _handle_events
    self._handle_recv()
  File "c:\python37\lib\site-packages\zmq\eventloop\zmqstream.py", line 486, in _handle_recv
    self._run_callback(callback, msg)
  File "c:\python37\lib\site-packages\zmq\eventloop\zmqstream.py", line 438, in _run_callback
    callback(*args, **kwargs)
  File "c:\python37\lib\site-packages\ipykernel\kernelbase.py", line 283, in dispatcher
    return self.dispatch_shell(stream, msg)
  File "c:\python37\lib\site-packages\ipykernel\kernelbase.py", line 233, in dispatch_shell
    self.pre_handler_hook()
  File "c:\python37\lib\site-packages\ipykernel\kernelbase.py", line 248, in pre_handler_hook
    self.saved_sigint_handler = signal(SIGINT, default_int_handler)
  File "c:\python37\lib\signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread
Traceback (most recent call last):
  File "c:\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\python37\lib\site-packages\ipykernel_launcher.py", line 16, in <module>
    app.launch_new_instance()
  File "c:\python37\lib\site-packages\traitlets\config\application.py", line 664, in launch_instance
    app.start()
  File "c:\python37\lib\site-packages\ipykernel\kernelapp.py", line 477, in start
    ioloop.IOLoop.instance().start()
  File "c:\python37\lib\site-packages\tornado\platform\asyncio.py", line 148, in start
    self.asyncio_loop.run_forever()
  File "c:\python37\lib\asyncio\base_events.py", line 521, in run_forever
    raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
[I 16:17:13.385 NotebookApp] KernelRestarter: restarting kernel (1/5), new random ports
Traceback (most recent call last):
  File "c:\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\python37\lib\site-packages\ipykernel_launcher.py", line 16, in <module>
    app.launch_new_instance()
  File "c:\python37\lib\site-packages\traitlets\config\application.py", line 664, in launch_instance
    app.start()
  File "c:\python37\lib\site-packages\ipykernel\kernelapp.py", line 477, in start
    ioloop.IOLoop.instance().start()
  File "c:\python37\lib\site-packages\tornado\platform\asyncio.py", line 148, in start
    self.asyncio_loop.run_forever()
  File "c:\python37\lib\asyncio\base_events.py", line 521, in run_forever
    raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
[I 16:17:16.385 NotebookApp] KernelRestarter: restarting kernel (2/5), new random ports
Traceback (most recent call last):
  File "c:\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\python37\lib\site-packages\ipykernel_launcher.py", line 16, in <module>
    app.launch_new_instance()
  File "c:\python37\lib\site-packages\traitlets\config\application.py", line 664, in launch_instance
    app.start()
  File "c:\python37\lib\site-packages\ipykernel\kernelapp.py", line 477, in start
    ioloop.IOLoop.instance().start()
  File "c:\python37\lib\site-packages\tornado\platform\asyncio.py", line 148, in start
    self.asyncio_loop.run_forever()
  File "c:\python37\lib\asyncio\base_events.py", line 521, in run_forever
    raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
[I 16:17:19.405 NotebookApp] KernelRestarter: restarting kernel (3/5), new random ports
Traceback (most recent call last):
  File "c:\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\python37\lib\site-packages\ipykernel_launcher.py", line 16, in <module>
    app.launch_new_instance()
  File "c:\python37\lib\site-packages\traitlets\config\application.py", line 664, in launch_instance
    app.start()
  File "c:\python37\lib\site-packages\ipykernel\kernelapp.py", line 477, in start
    ioloop.IOLoop.instance().start()
  File "c:\python37\lib\site-packages\tornado\platform\asyncio.py", line 148, in start
    self.asyncio_loop.run_forever()
  File "c:\python37\lib\asyncio\base_events.py", line 521, in run_forever
    raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
[I 16:17:22.415 NotebookApp] KernelRestarter: restarting kernel (4/5), new random ports
Traceback (most recent call last):
  File "c:\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\python37\lib\site-packages\ipykernel_launcher.py", line 16, in <module>
    app.launch_new_instance()
  File "c:\python37\lib\site-packages\traitlets\config\application.py", line 664, in launch_instance
    app.start()
  File "c:\python37\lib\site-packages\ipykernel\kernelapp.py", line 477, in start
    ioloop.IOLoop.instance().start()
  File "c:\python37\lib\site-packages\tornado\platform\asyncio.py", line 148, in start
    self.asyncio_loop.run_forever()
  File "c:\python37\lib\asyncio\base_events.py", line 521, in run_forever
    raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
[W 16:17:25.415 NotebookApp] KernelRestarter: restart failed
[W 16:17:25.415 NotebookApp] Kernel cc500446-cf7d-4c96-9952-30211013ac14 died, removing from map.
[W 16:17:31.476 NotebookApp] Replacing stale connection: cc500446-cf7d-4c96-9952-30211013ac14:b83fe93a3ee540b6a74e9ed030e1fdbc

Most helpful comment

The current versions of ipykernel and ipython are 5.3.4 and 7.17.0, respectively.

I recommend running the following: pip install --upgrade ipykernel ipython

All 6 comments

Please ensure your ipython and ipykernel packages are up to date. If that doesn't help, please provide the output of:

jupyter --version

Thank you for reply, here it is output

````
C:\Users\dell>jupyter --version
jupyter core : 4.6.1
jupyter-notebook : 6.1.1
qtconsole : 4.6.0
ipython : 7.10.2
ipykernel : 4.6.1
jupyter client : 5.3.4
jupyter lab : 1.2.4
nbconvert : 5.6.1
ipywidgets : 7.5.1
nbformat : 4.4.0
traitlets : 4.3.3

C:\Users\dell>
```

The current versions of ipykernel and ipython are 5.3.4 and 7.17.0, respectively.

I recommend running the following: pip install --upgrade ipykernel ipython

Thanks a lot, it's worked.

Right on - closing issue.

For future visitors, I still had this error message within one of my notebooks with the latest version installed. One possible source of the problem is when you have %run other_notebook.ipynb, and in other_notebook there is a semantic error in the code. Try executing the cells in that notebook to localize the problem.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pylang picture pylang  路  3Comments

okdolly-001 picture okdolly-001  路  3Comments

cmesro picture cmesro  路  3Comments

arbaazsama picture arbaazsama  路  3Comments

jonatanblue picture jonatanblue  路  3Comments