Skip to content

Commit c9ee5dd

Browse files
author
Daniele Briggi
committed
fix(seg-fault): attempt
1 parent 6f2aa0a commit c9ee5dd

File tree

5 files changed

+55
-24
lines changed

5 files changed

+55
-24
lines changed

.devcontainer/devcontainer.json

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
{
22
"name": "Python 3.10",
33
"image": "mcr.microsoft.com/devcontainers/python:3.10",
4-
"runArgs": [
5-
"--runtime",
6-
"nvidia",
7-
"--gpus",
8-
"all",
9-
// optional but make sure CUDA workloads are available
10-
"--env",
11-
"NVIDIA_VISIBLE_DEVICES=all",
12-
// optional but make sure CUDA workloads are available
13-
"--env",
14-
"NVIDIA_DRIVER_CAPABILITIES=compute,utility"
15-
],
164
"customizations": {
175
"vscode": {
186
"extensions": [
@@ -26,13 +14,5 @@
2614
"hbenl.vscode-test-explorer"
2715
]
2816
}
29-
},
30-
"hostRequirements": {
31-
"gpu": "optional"
32-
},
33-
"remoteEnv": {
34-
// optional but make sure CUDA workloads are available
35-
"NVIDIA_VISIBLE_DEVICES": "all",
36-
"NVIDIA_DRIVER_CAPABILITIES": "compute,utility"
3717
}
3818
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "Python 3.11",
3+
"image": "mcr.microsoft.com/devcontainers/python:3.11",
4+
"runArgs": [
5+
"--runtime",
6+
"nvidia",
7+
"--gpus",
8+
"all",
9+
// optional but make sure CUDA workloads are available
10+
"--env",
11+
"NVIDIA_VISIBLE_DEVICES=all",
12+
// optional but make sure CUDA workloads are available
13+
"--env",
14+
"NVIDIA_DRIVER_CAPABILITIES=compute,utility"
15+
],
16+
"customizations": {
17+
"vscode": {
18+
"extensions": [
19+
"ms-python.black-formatter",
20+
"ms-python.flake8",
21+
"ms-python.isort",
22+
"ms-python.vscode-pylance",
23+
"ms-python.python",
24+
"ms-python.debugpy",
25+
"ms-python.vscode-python-envs",
26+
"hbenl.vscode-test-explorer"
27+
]
28+
}
29+
},
30+
"hostRequirements": {
31+
"gpu": "optional"
32+
},
33+
"remoteEnv": {
34+
// optional but make sure CUDA workloads are available
35+
"NVIDIA_VISIBLE_DEVICES": "all",
36+
"NVIDIA_DRIVER_CAPABILITIES": "compute,utility"
37+
}
38+
}

.github/workflows/test.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ jobs:
4949
5050
- name: Test
5151
# Using default directory for models
52+
# COVERAGE_CORE=pytrace: Workaround for Python 3.11 segfault with SQLite extensions + C tracer
53+
# See: https://github.com/nedbat/coveragepy/issues/1665
54+
env:
55+
COVERAGE_CORE: ${{ matrix.python-version == '3.11' && 'pytrace' || '' }}
5256
run: |
5357
pytest --cov --cov-branch --cov-report=xml -v -m "not slow" ./tests
5458

src/sqlite_rag/models/document_result.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ def get_preview(
4242
return self.chunk_content[:max_chars]
4343

4444
# Sort by start_offset to maintain document order
45-
top_sentences.sort(
46-
key=lambda s: s.start_offset if s.start_offset is not None else -1
45+
top_sentences = sorted(
46+
top_sentences,
47+
key=lambda s: s.start_offset if s.start_offset is not None else -1,
4748
)
4849

4950
preview_parts = []

tests/conftest.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sqlite3
22
import tempfile
3+
from collections.abc import Generator
34

45
import pytest
56

@@ -26,7 +27,7 @@ def db_conn():
2627

2728

2829
@pytest.fixture
29-
def engine(db_conn) -> Engine:
30+
def engine(db_conn) -> Generator[Engine, None, None]:
3031
conn, settings = db_conn
3132

3233
engine = Engine(
@@ -39,4 +40,11 @@ def engine(db_conn) -> Engine:
3940
engine.quantize()
4041
engine.create_new_context()
4142

42-
return engine
43+
yield engine
44+
45+
# Cleanup resources to prevent segfaults in Python 3.11
46+
# Must explicitly free resources before garbage collection
47+
try:
48+
engine.close()
49+
except Exception:
50+
pass

0 commit comments

Comments
 (0)