Skip to content

Commit f6c5b62

Browse files
this fixes the db is lcoked errors
1 parent 0373b3d commit f6c5b62

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

pioreactor/tests/test_utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,19 @@ def test_caches_will_delete_when_asked() -> None:
7474
assert "test" not in cache
7575

7676

77+
def test_caches_pop() -> None:
78+
with local_intermittent_storage("test") as cache:
79+
cache.empty()
80+
81+
with local_intermittent_storage("test") as cache:
82+
cache["A"] = "1"
83+
84+
with local_intermittent_storage("test") as cache:
85+
assert cache.pop("A") == "1"
86+
assert cache.pop("B") is None
87+
assert cache.pop("C", default=3) == 3
88+
89+
7790
def test_caches_can_have_tuple_or_singleton_keys() -> None:
7891
with local_persistent_storage("test_caches_can_have_tuple_keys") as c:
7992
c[(1, 2)] = 1

pioreactor/utils/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def __enter__(self):
348348
PRAGMA cache_size = -4000;
349349
"""
350350
)
351-
self.cursor.execute("BEGIN")
351+
self.cursor.execute("BEGIN IMMEDIATE")
352352
self._initialize_table()
353353
return self
354354

@@ -394,9 +394,8 @@ def iterkeys(self):
394394
return (self.convert_key(row[0]) for row in self.cursor.fetchall())
395395

396396
def pop(self, key, default=None):
397-
self.cursor.execute(f"SELECT value FROM {self.table_name} WHERE key = ?", (key,))
397+
self.cursor.execute(f"DELETE FROM {self.table_name} WHERE key = ? RETURNING value", (key,))
398398
result = self.cursor.fetchone()
399-
self.cursor.execute(f"DELETE FROM {self.table_name} WHERE key = ?", (key,))
400399

401400
if result is None:
402401
return default
@@ -647,6 +646,7 @@ def __init__(self) -> None:
647646
)
648647
self.cursor = self.conn.cursor()
649648
self._create_tables()
649+
self.cursor.execute("BEGIN IMMEDIATE")
650650

651651
def _create_tables(self) -> None:
652652
# TODO: add a created_at, updated_at to pio_job_published_settings

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[pytest]
22
testpaths=pioreactor/tests/
3-
addopts = --random-order
3+
addopts = --random-order -s -vv

0 commit comments

Comments
 (0)