mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-06 09:28:34 +00:00
fix(agent): snapshot active tasks before cancellation
This commit is contained in:
parent
ce3e532643
commit
78cf68c291
@ -760,7 +760,7 @@ class AgentLoop:
|
|||||||
|
|
||||||
Returns the total number of cancelled tasks + subagents.
|
Returns the total number of cancelled tasks + subagents.
|
||||||
"""
|
"""
|
||||||
tasks = self._active_tasks.pop(key, set())
|
tasks = tuple(self._active_tasks.pop(key, set()))
|
||||||
cancelled = sum(1 for t in tasks if not t.done() and t.cancel())
|
cancelled = sum(1 for t in tasks if not t.done() and t.cancel())
|
||||||
for t in tasks:
|
for t in tasks:
|
||||||
with suppress(asyncio.CancelledError, Exception):
|
with suppress(asyncio.CancelledError, Exception):
|
||||||
|
|||||||
@ -73,7 +73,9 @@ class TestHandleStop:
|
|||||||
|
|
||||||
task = asyncio.create_task(slow_task())
|
task = asyncio.create_task(slow_task())
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
loop._active_tasks["test:c1"] = {task}
|
active_tasks = {task}
|
||||||
|
loop._active_tasks["test:c1"] = active_tasks
|
||||||
|
task.add_done_callback(active_tasks.discard)
|
||||||
|
|
||||||
msg = InboundMessage(channel="test", sender_id="u1", chat_id="c1", content="/stop")
|
msg = InboundMessage(channel="test", sender_id="u1", chat_id="c1", content="/stop")
|
||||||
ctx = CommandContext(msg=msg, session=None, key=msg.session_key, raw="/stop", loop=loop)
|
ctx = CommandContext(msg=msg, session=None, key=msg.session_key, raw="/stop", loop=loop)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user