"Database is locked"
https://gitlab.com/samthursfield/calliope/-/jobs/5602608752
_____________________ test_concurrent_writes[SqliteCache] ______________________
kind = <class 'calliope.cache.SqliteCache'>
tmpdir = local('/tmp/pytest-of-root/pytest-0/test_concurrent_writes_SqliteC0')
@pytest.mark.parametrize("kind", KINDS)
def test_concurrent_writes(kind, tmpdir):
"""Test that two threads can write to the same cache file at once."""
class Thread1(threading.Thread):
def run(self):
cache = kind("benchmark", cachedir=tmpdir)
for i in range(0, 1000):
key = "test:%i" % i
test_data = 100 * chr((i % 26) + 65)
cache.store(key, test_data)
class Thread2(threading.Thread):
def run(self):
cache = kind("benchmark", cachedir=tmpdir)
for i in range(500, 1500):
key = "test:%i" % i
test_data = 100 * chr((i % 26) + 65)
cache.store(key, test_data)
t1 = Thread1()
t2 = Thread2()
t1.start()
t2.start()
t1.join()
t2.join()
cache = kind("benchmark", cachedir=tmpdir)
for i in range(0, 1500):
found, value = cache.lookup("test:%i" % i)
> assert found, f"key 'test:{i}' was not found in the cache!"
E AssertionError: key 'test:1000' was not found in the cache!
E assert None
tests/test_cache.py:228: AssertionError
=============================== warnings summary ===============================
tests/test_cache.py::test_concurrent_writes[SqliteCache]
/builds/samthursfield/calliope/.tox/py310/lib/python3.10/site-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-2
Traceback (most recent call last):
File "/usr/local/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/builds/samthursfield/calliope/tests/test_cache.py", line 216, in run
cache.store(key, test_data)
File "/builds/samthursfield/calliope/.tox/py310/lib/python3.10/site-packages/calliope/cache.py", line 232, in store
db = self._connection()
File "/builds/samthursfield/calliope/.tox/py310/lib/python3.10/site-packages/calliope/cache.py", line 183, in _connection
self.__connection.execute("PRAGMA journal_mode=WAL;")
sqlite3.OperationalError: database is locked
warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg))
This has been happening for years.
Is write-ahead logging mode needed? https://www.sqlite.org/lockingv3.html