File tree Expand file tree Collapse file tree
src/claude_agent_sdk/_internal Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -99,7 +99,11 @@ def _mark_done(self, exc: BaseException | None) -> None:
9999 self ._exception = exc
100100 self ._done_event .set ()
101101 for cb in self ._callbacks :
102- with suppress (Exception ):
102+ # Suppress BaseException so a misbehaving callback can never
103+ # propagate out of the system-task _runner (which would crash
104+ # trio with TrioInternalError). The actual callbacks used here
105+ # are set.discard / dict.pop, so this is purely defensive.
106+ with suppress (BaseException ):
103107 cb (self )
104108 self ._callbacks .clear ()
105109
@@ -146,6 +150,9 @@ async def _runner() -> None:
146150
147151 trio .lowlevel .spawn_system_task (_runner )
148152 return handle
153+ # Unsupported backend: close the coroutine so we don't leak a "coroutine
154+ # was never awaited" RuntimeWarning on top of the RuntimeError.
155+ coro .close ()
149156 raise RuntimeError (
150157 f"Unsupported async backend: { backend !r} . "
151158 "claude_agent_sdk requires asyncio or trio."
You can’t perform that action at this time.
0 commit comments