From d3e427c8d95e551e4b40c288c445fd99b4762ff5 Mon Sep 17 00:00:00 2001 From: wozeparrot Date: Wed, 7 Aug 2024 14:38:19 -0700 Subject: [PATCH] fix sqlite3 locks (#5971) --- tinygrad/helpers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tinygrad/helpers.py b/tinygrad/helpers.py index 9bf029f1d5..df9d794857 100644 --- a/tinygrad/helpers.py +++ b/tinygrad/helpers.py @@ -209,7 +209,9 @@ def db_connection(): if _db_connection is None: os.makedirs(CACHEDB.rsplit(os.sep, 1)[0], exist_ok=True) _db_connection = sqlite3.connect(CACHEDB, timeout=60, isolation_level="IMMEDIATE") - _db_connection.execute("PRAGMA journal_mode=WAL").fetchone() + # another connection has set it already or is in the process of setting it + # that connection will lock the database + with contextlib.suppress(sqlite3.OperationalError): _db_connection.execute("PRAGMA journal_mode=WAL").fetchone() if DEBUG >= 7: _db_connection.set_trace_callback(print) return _db_connection