From 60fd49ea601a2e37c3d00b1531605924c4e116a0 Mon Sep 17 00:00:00 2001 From: mannaandpoem <1580466765@qq.com> Date: Wed, 13 Mar 2024 16:52:53 +0800 Subject: [PATCH 1/2] update method of terminate --- metagpt/actions/di/execute_nb_code.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/metagpt/actions/di/execute_nb_code.py b/metagpt/actions/di/execute_nb_code.py index f6a8defbd..b16da221f 100644 --- a/metagpt/actions/di/execute_nb_code.py +++ b/metagpt/actions/di/execute_nb_code.py @@ -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() + + # Stops all the running channels for this kernel + # The stdin_channel is the channel for handling standard input to the kernel. + if self.nb_client.kc.stdin_channel.is_alive(): + self.nb_client.kc.stdin_channel.stop() + # The hb_channel is the channel for heartbeat communication between the kernel and client. + if self.nb_client.kc.hb_channel.is_alive(): + self.nb_client.kc.hb_channel.stop() + # The control_channel is the channel for controlling the kernel. + if self.nb_client.kc.control_channel.is_alive(): + self.nb_client.kc.control_channel.stop() + + self.nb_client.kc = None + self.nb_client.km = None async def reset(self): """reset NotebookClient""" From 88cea9418c94b9d4607fdd06dc995780b5eeb7e3 Mon Sep 17 00:00:00 2001 From: mannaandpoem <1580466765@qq.com> Date: Wed, 13 Mar 2024 17:08:58 +0800 Subject: [PATCH 2/2] update method of terminate --- metagpt/actions/di/execute_nb_code.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/metagpt/actions/di/execute_nb_code.py b/metagpt/actions/di/execute_nb_code.py index b16da221f..0cf16b70f 100644 --- a/metagpt/actions/di/execute_nb_code.py +++ b/metagpt/actions/di/execute_nb_code.py @@ -61,16 +61,16 @@ class ExecuteNbCode(Action): 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 - # The stdin_channel is the channel for handling standard input to the kernel. - if self.nb_client.kc.stdin_channel.is_alive(): - self.nb_client.kc.stdin_channel.stop() - # The hb_channel is the channel for heartbeat communication between the kernel and client. - if self.nb_client.kc.hb_channel.is_alive(): - self.nb_client.kc.hb_channel.stop() - # The control_channel is the channel for controlling the kernel. - if self.nb_client.kc.control_channel.is_alive(): - self.nb_client.kc.control_channel.stop() + for channel in channels: + if channel.is_alive(): + channel.stop() self.nb_client.kc = None self.nb_client.km = None