Skip to content

Commit fc0a272

Browse files
author
Murat Kaan Meral
committed
fix: improve graph timeout
1 parent d4f5571 commit fc0a272

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

src/strands/multiagent/graph.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -503,20 +503,9 @@ async def _stream_with_timeout(
503503
self, async_generator: AsyncIterator[dict[str, Any]], timeout: float, timeout_message: str
504504
) -> AsyncIterator[dict[str, Any]]:
505505
"""Wrap an async generator with timeout functionality."""
506-
507-
# Create a task for the entire generator with timeout
508-
async def generator_with_timeout() -> AsyncIterator[dict[str, Any]]:
509-
try:
510-
async for event in async_generator:
511-
yield event
512-
except asyncio.TimeoutError:
513-
raise Exception(timeout_message) from None
514-
515-
# Use asyncio.wait_for on each individual event
516-
generator = generator_with_timeout()
517506
while True:
518507
try:
519-
event = await asyncio.wait_for(generator.__anext__(), timeout=timeout)
508+
event = await asyncio.wait_for(async_generator.__anext__(), timeout=timeout)
520509
yield event
521510
except StopAsyncIteration:
522511
break

0 commit comments

Comments
 (0)