jupyter / jupyter_client

Jupyter protocol client APIs
https://jupyter-client.readthedocs.io
BSD 3-Clause "New" or "Revised" License
374 stars 279 forks source link

Exception raised in KernelClient.del when shutting down kernel after executing code using kc.execute_interactive() #1026

Open vivekvedant opened 1 month ago

vivekvedant commented 1 month ago

Description When executing the provided code snippet to start a new kernel and execute a Python statement using kc.execute_interactive, the code executes successfully, but it raises an exception related to KernelClient.del upon exiting.

Steps to Reproduce Run the following Python code:

from jupyter_client.manager import KernelManager, start_new_kernel
from IPython.utils.capture import capture_output

km, kc = start_new_kernel(kernel_name="python3")

TIMEOUT = 30
with capture_output() as io:
    reply = kc.execute_interactive("print('hello world')", timeout=TIMEOUT)
km.shutdown_kernel()

print(io.stdout)
print(io.stderr)

Expected Behavior The code should execute the provided Python statement (print('hello world')) in the newly started kernel and print "hello world" to the standard output. After execution, it should cleanly exit without raising any exceptions.

Actual Behavior The code executes successfully and prints "hello world" as expected, but upon exiting, it raises the following exception:

hello world

Exception ignored in: <function KernelClient.__del__ at 0x7f706835dea0>
Traceback (most recent call last):
  File "/home/vivek/zeza/AIDEN_experiment/sandbox/jupyter_client/jupyter_client/client.py", line 121, in __del__
  File "/home/vivek/miniconda3/envs/test/lib/python3.10/site-packages/traitlets/traitlets.py", line 687, in __get__
  File "/home/vivek/miniconda3/envs/test/lib/python3.10/site-packages/traitlets/traitlets.py", line 666, in get
TypeError: 'NoneType' object is not callable

Environment Python version: 3.10.14 Operating System: Ubuntu 22.04 jupyter_client version: 8.6.2

mwohlf commented 2 weeks ago

same issue here