Merge pull request #1002 from mannaandpoem/code_interpreter_update_terminate

update method of terminate
This commit is contained in:
garylin2099 2024-03-13 20:13:32 +08:00 committed by GitHub
commit 9f0ed61a15
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -57,8 +57,23 @@ class ExecuteNbCode(Action):
async def terminate(self):
"""kill NotebookClient"""
if self.nb_client.km is not None:
await self.nb_client._async_cleanup_kernel()
if self.nb_client.km is not None and await self.nb_client.km.is_alive():
await self.nb_client.km.shutdown_kernel(now=True)
await self.nb_client.km.cleanup_resources()
channels = [
self.nb_client.kc.stdin_channel, # The channel for handling standard input to the kernel.
self.nb_client.kc.hb_channel, # The channel for heartbeat communication between the kernel and client.
self.nb_client.kc.control_channel, # The channel for controlling the kernel.
]
# Stops all the running channels for this kernel
for channel in channels:
if channel.is_alive():
channel.stop()
self.nb_client.kc = None
self.nb_client.km = None
async def reset(self):
"""reset NotebookClient"""