mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-11 22:04:37 +00:00
core: in astream_events v2 always await task even if already finished (#22916)
- this ensures exceptions propagate to the caller
This commit is contained in:
parent
513e491ce9
commit
338180f383
@ -940,9 +940,10 @@ async def _astream_events_implementation_v2(
|
|||||||
|
|
||||||
yield event
|
yield event
|
||||||
finally:
|
finally:
|
||||||
# Wait for the runnable to finish, if not cancelled (eg. by break)
|
# Cancel the task if it's still running
|
||||||
if task.cancel():
|
task.cancel()
|
||||||
try:
|
# Await it anyway, to run any cleanup code, and propagate any exceptions
|
||||||
await task
|
try:
|
||||||
except asyncio.CancelledError:
|
await task
|
||||||
pass
|
except asyncio.CancelledError:
|
||||||
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user