Skip to content

Commit

Permalink
Mark cancelled as seen
Browse files Browse the repository at this point in the history
  • Loading branch information
nfcampos committed Jul 1, 2024
1 parent 3506be1 commit dfdb4d0
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion libs/langgraph/langgraph/pregel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,11 @@ def put_checkpoint(metadata: CheckpointMetadata) -> Iterator[Any]:
except NameError:
pass
# wait for all background tasks to finish
await asyncio.shield(asyncio.gather(*bg))
fut = asyncio.gather(*bg)
# mark the exception as retrieved
fut.add_done_callback(_mark_cancelled_as_seen)
# wait for the future to finish, shielded from cancellation
await asyncio.shield(fut)

def invoke(
self,
Expand Down Expand Up @@ -2021,3 +2025,10 @@ def _with_mode(mode: StreamMode, on: bool, iter: Iterator[Any]) -> Iterator[Any]
yield (mode, chunk)
else:
yield from iter


def _mark_cancelled_as_seen(fut: concurrent.futures.Future) -> None:
try:
fut.exception()
except (asyncio.CancelledError, concurrent.futures.CancelledError):
pass

0 comments on commit dfdb4d0

Please sign in to comment.