Skip to content

Commit e07c9f0

Browse files
committed
suppress cancel scope error
1 parent 6158742 commit e07c9f0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pydantic_ai_slim/pydantic_ai/result.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -732,9 +732,13 @@ def _async_iterator_to_sync(
732732
func: Callable[[StreamedRunResult[AgentDepsT, OutputDataT]], AsyncIterator[T]],
733733
) -> Iterator[T]:
734734
async def my_task():
735-
async with self._with_streamed_run_result() as result:
736-
async for item in func(result):
737-
yield item
735+
try:
736+
async with self._with_streamed_run_result() as result:
737+
async for item in func(result):
738+
yield item
739+
except RuntimeError as e:
740+
if str(e) != 'Attempted to exit cancel scope in a different task than it was entered in':
741+
raise
738742

739743
return _utils.sync_async_iterator(my_task())
740744

0 commit comments

Comments
 (0)