Skip to content

Commit deadc75

Browse files
HumanBean17claude
andcommitted
fix(tests): set num_threads=1 on Kuzu Connection to avoid asyncio conflicts
The segfault was caused by pytest-asyncio's background event loop thread conflicting with Kuzu's internal threading. Setting num_threads=1 on Connection initialization avoids this conflict. Changes: - KuzuGraph.__init__: Set num_threads=1 on Connection - conftest kuzu_db_path fixture: Set num_threads=1 - test_kuzu_queries helper: Set num_threads=1 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 6b76c64 commit deadc75

3 files changed

Lines changed: 4 additions & 3 deletions

File tree

kuzu_queries.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ class KuzuGraph:
337337
def __init__(self, db_path: str) -> None:
338338
self.db_path = db_path
339339
self._db = kuzu.Database(db_path, read_only=True)
340-
self._conn = kuzu.Connection(self._db)
340+
# num_threads=1 avoids internal threading that conflicts with pytest-asyncio
341+
self._conn = kuzu.Connection(self._db, num_threads=1)
341342
self._conn_lock = threading.Lock()
342343

343344
def close(self) -> None:

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def kuzu_db_path(tmp_path_factory, corpus_root: Path) -> Path:
6161
build_kuzu_to(corpus_root, db_path, max_pass=5)
6262

6363
db = kuzu.Database(str(db_path), read_only=True)
64-
conn = kuzu.Connection(db)
64+
conn = kuzu.Connection(db, num_threads=1)
6565
n_types = 0
6666
r = conn.execute("MATCH (s:Symbol) WHERE s.kind = 'class' RETURN count(*) AS n")
6767
if r.has_next():

tests/test_kuzu_queries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def test_trace_flow_empty_seeds_returns_empty(kuzu_graph) -> None:
376376
def _open_stale_ontology_graph(tmp_path: Path, ontology_version: int) -> Path:
377377
db_path = tmp_path / f"stale_ontology_{ontology_version}.kuzu"
378378
db = kuzu.Database(str(db_path))
379-
conn = kuzu.Connection(db)
379+
conn = kuzu.Connection(db, num_threads=1)
380380
conn.execute(
381381
"CREATE NODE TABLE GraphMeta("
382382
"key STRING PRIMARY KEY, "

0 commit comments

Comments
 (0)