jupyter / jupyter_console

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

KeyboardInterrupt not handled correctly #296

Open allefeld opened 9 months ago

allefeld commented 9 months ago

If I interrupt via Ctrl+C a long-running computation, here simulated by time.sleep, Jupyter Console gets confused:

$ jupyter console
Jupyter console 6.6.3

Python 3.10.12 | packaged by conda-forge | (main, Jun 23 2023, 22:40:32) [GCC 12.3.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.15.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from time import sleep

In [2]: sleep(15)
^C
KeyboardInterrupt escaped interact()

In [3]: 2+2🤫/lib/python3.10/site-packages/jupyter_console/ptshell.py:787: UserWarning: The kernel did not respond to an is_complete_request. Setting `use_kernel_is_complete` to False.
  warn('The kernel did not respond to an is_complete_request. '
In [3]: 2+2

Out[3]: 4

🤫 replaces the path to my Conda environment.

By "confused" I mean:

I first encountered this problem with a Python wrapper kernel I'm developing, but then tested with the default Python kernel. The same thing happens in both, which leads me to believe that this is a bug in Jupyter Console. From what I can tell, the kernel is never notified about the interruption.