Streamlit with LangGraph persistence - sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 10648 and this is thread id 11516

Hi, I’m trying to run a streamlit app with LangGraph and persistence following this tutorial:

However, when I spin it in a streamlit app I get the error:
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 10648 and this is thread id 11516.

How can I “save” the same thread so that the persistence is kept and the messages with LangGraph are saved after each new message?

Thank you

Could you show your streamlit code?

I was able to fix it, thanks

You need to tell sqlite not to do thread-checking but the SqliteSaver.from_conn_string_method doesn’t allow the check_same_thread paramterer to be specified. a work around is to add a class method as follows:

def from_conn_stringx(cls, conn_string: str,) → “SqliteSaver”:
return SqliteSaver(conn=sqlite3.connect(conn_string, check_same_thread=False))
SqliteSaver.from_conn_stringx=classmethod(from_conn_stringx)

I have a working streamlit app here and source in github

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.