mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-02 04:12:45 +02:00
Merge pull request #977 from orange-crow/fix_ipykernel_error
Fix ipykernel error in _plan_and_act of Interpreter.
This commit is contained in:
commit
543f519deb
3 changed files with 15 additions and 1 deletions
|
|
@ -58,7 +58,8 @@ class ExecuteNbCode(Action):
|
|||
|
||||
async def terminate(self):
|
||||
"""kill NotebookClient"""
|
||||
await self.nb_client._async_cleanup_kernel()
|
||||
if self.nb_client.km is not None:
|
||||
await self.nb_client._async_cleanup_kernel()
|
||||
|
||||
async def reset(self):
|
||||
"""reset NotebookClient"""
|
||||
|
|
|
|||
|
|
@ -42,6 +42,10 @@ class Interpreter(Role):
|
|||
def working_memory(self):
|
||||
return self.rc.working_memory
|
||||
|
||||
async def _plan_and_act(self) -> Message:
|
||||
await super()._plan_and_act()
|
||||
await self.execute_code.terminate()
|
||||
|
||||
async def _act_on_task(self, current_task: Task) -> TaskResult:
|
||||
code, result, is_success = await self._write_and_exec_code()
|
||||
task_result = TaskResult(code=code, result=result, is_success=is_success)
|
||||
|
|
|
|||
|
|
@ -104,6 +104,15 @@ async def test_terminate():
|
|||
|
||||
time.sleep(2)
|
||||
assert executor.nb_client.km is None
|
||||
for _ in range(200):
|
||||
executor = ExecuteNbCode()
|
||||
await executor.run(code='print("This is a code!")', language="python")
|
||||
is_kernel_alive = await executor.nb_client.km.is_alive()
|
||||
assert is_kernel_alive
|
||||
await executor.terminate()
|
||||
assert executor.nb_client.km is None
|
||||
assert executor.nb_client.kc is None
|
||||
await executor.terminate()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue