From 9242998db11bc4d7b7f454838733914105b685d4 Mon Sep 17 00:00:00 2001 From: Junlin Zhou Date: Wed, 24 May 2023 07:46:50 +0800 Subject: [PATCH] Empty check before pop (#4929) # Check whether 'other' is empty before popping This PR could fix a potential 'popping empty set' error. Co-authored-by: Junlin Zhou --- langchain/callbacks/streaming_aiter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/langchain/callbacks/streaming_aiter.py b/langchain/callbacks/streaming_aiter.py index 47372dd9..cc66d9a4 100644 --- a/langchain/callbacks/streaming_aiter.py +++ b/langchain/callbacks/streaming_aiter.py @@ -58,7 +58,8 @@ class AsyncIteratorCallbackHandler(AsyncCallbackHandler): ) # Cancel the other task - other.pop().cancel() + if other: + other.pop().cancel() # Extract the value of the first completed task token_or_done = cast(Union[str, Literal[True]], done.pop().result())