Skip to content

armgit / burr

Public Imported from GitHub
0

Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.

Adds option to remove thread check on sqlite persister for streamlit

elijahbenizzya52f17577fe9
diff --git a/burr/core/persistence.py b/burr/core/persistence.py
index d99d29e8..51bf76f2 100644
--- a/burr/core/persistence.py
+++ b/burr/core/persistence.py
@@ -142,16 +142,26 @@ class SQLLitePersister(BaseStatePersister):
PARTITION_KEY_DEFAULT = ""
- def __init__(self, db_path: str, table_name: str = "burr_state", serde_kwargs: dict = None):
+ def __init__(
+ self,
+ db_path: str,
+ table_name: str = "burr_state",
+ serde_kwargs: dict = None,
+ connect_kwargs: dict = None,
+ ):
"""Constructor
:param db_path: the path the DB will be stored.
:param table_name: the table name to store things under.
:param serde_kwargs: kwargs for state serialization/deserialization.
+ :param connect_kwargs: kwargs to pass to the sqlite3.connect method.
+ Use check_same_thread=False to enable use ina multithreaded context
"""
self.db_path = db_path
self.table_name = table_name
- self.connection = sqlite3.connect(db_path)
+ self.connection = sqlite3.connect(
+ db_path, **connect_kwargs if connect_kwargs is not None else {}
+ )
self.serde_kwargs = serde_kwargs or {}
def create_table_if_not_exists(self, table_name: str):
diff --git a/examples/hello-world-counter/application.py b/examples/hello-world-counter/application.py
index d160dd83..ee360b8d 100644
--- a/examples/hello-world-counter/application.py
+++ b/examples/hello-world-counter/application.py
@@ -24,7 +24,7 @@ def application(
storage_dir: Optional[str] = "~/.burr",
hooks: Optional[List[LifecycleAdapter]] = None,
) -> Application:
- persister = SQLLitePersister("demos.db", "counter")
+ persister = SQLLitePersister("demos.db", "counter", connect_kwargs={"check_same_thread": False})
persister.initialize()
logger.info(
f"{partition_key} has these prior invocations: {persister.list_app_ids(partition_key)}"