From bccea30c2a46700d381a6c9a95857a761bb3bb32 Mon Sep 17 00:00:00 2001 From: William FH <13333726+hinthornw@users.noreply.github.com> Date: Thu, 27 Jun 2024 12:59:26 -0700 Subject: [PATCH] [Docstrings] Add reminder to close connection (#864) In AsyncSqliteSaver, otherwise your program will "hang". Recommend using async with AsyncSqliteSaver.from_conn_str(...). --- .../langgraph/langgraph/checkpoint/aiosqlite.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libs/langgraph/langgraph/checkpoint/aiosqlite.py b/libs/langgraph/langgraph/checkpoint/aiosqlite.py index ad0fe7bb6..b636e02d3 100644 --- a/libs/langgraph/langgraph/checkpoint/aiosqlite.py +++ b/libs/langgraph/langgraph/checkpoint/aiosqlite.py @@ -46,6 +46,23 @@ class AsyncSqliteSaver(BaseCheckpointSaver, AbstractAsyncContextManager): for production workloads, due to limitations in SQLite's write performance. For production workloads, consider using a more robust database like PostgreSQL. + !!! Important + Remember to **close the database connection** after executing your code, + otherwise, you may see the graph "hang" after execution (since the program + will not exit until the connection is closed). + + The easiest way to do this is to use the `async with` statement, as shown in the + examples below. + + ```python + async with AsyncSqliteSaver.from_conn_string("checkpoints.sqlite") as saver: + # Your code here + graph = builder.compile(checkpointer=saver) + config = {"configurable": {"thread_id": "thread-1"}} + async for event in graph.astream_events(..., config, version="v1"): + print(event) + ``` + Args: conn (aiosqlite.Connection): The asynchronous SQLite database connection. serde (Optional[SerializerProtocol]): The serializer to use for serializing and deserializing checkpoints. Defaults to JsonPlusSerializerCompat.