Skip to content

Commit c925f26

Browse files
committed
Fix unclosed file warnings in json.load() calls
The json.load(open(...)) pattern leaves file handles open, causing ResourceWarning when Python is run with warnings enabled. This is particularly noisy when using multiprocessing, as each worker triggers the warning when importing the module. Changes: - neuropixels_tools.py: Use context manager in _load_np_probe_features() - testing.py: Use context manager when loading JSON schema Both files now properly close file handles using 'with' statements. Fixes issue reported for Python 3.14 on Linux with forkserver multiprocessing.
1 parent bbeb144 commit c925f26

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/probeinterface/neuropixels_tools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def _load_np_probe_features():
2828
global _np_probe_features
2929
if _np_probe_features is None:
3030
probe_features_filepath = Path(__file__).absolute().parent / Path("resources/neuropixels_probe_features.json")
31-
_np_probe_features = json.load(open(probe_features_filepath, "r"))
31+
with open(probe_features_filepath, "r") as f:
32+
_np_probe_features = json.load(f)
3233
return _np_probe_features
3334

3435

src/probeinterface/testing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from probeinterface import __version__ as version
55

66
json_schema_file = Path(__file__).absolute().parent / "schema" / "probe.json.schema"
7-
schema = json.load(open(json_schema_file, "r"))
7+
with open(json_schema_file, "r") as f:
8+
schema = json.load(f)
89

910

1011
def validate_probe_dict(probe_dict):

0 commit comments

Comments
 (0)