mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-04 08:42:38 +00:00
fix: ensure stream is closed on exit
This commit is contained in:
@@ -264,6 +264,7 @@ async def send_message_and_get_task_id(
|
||||
Returns:
|
||||
Task ID string if agent needs polling/waiting, or TaskStateResult if done.
|
||||
"""
|
||||
try:
|
||||
async for event in event_stream:
|
||||
if isinstance(event, Message):
|
||||
new_messages.append(event)
|
||||
@@ -312,3 +313,8 @@ async def send_message_and_get_task_id(
|
||||
error="No task ID received from initial message",
|
||||
history=new_messages,
|
||||
)
|
||||
|
||||
finally:
|
||||
aclose = getattr(event_stream, "aclose", None)
|
||||
if aclose:
|
||||
await aclose()
|
||||
|
||||
@@ -133,6 +133,11 @@ class StreamingHandler:
|
||||
history=new_messages,
|
||||
)
|
||||
|
||||
finally:
|
||||
aclose = getattr(event_stream, "aclose", None)
|
||||
if aclose:
|
||||
await aclose()
|
||||
|
||||
if final_result:
|
||||
return final_result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user