From c925f2617a9678a764b957b062a98a9f79abea45 Mon Sep 17 00:00:00 2001 From: Graham Findlay Date: Tue, 13 Jan 2026 16:53:55 +0000 Subject: [PATCH] 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. --- src/probeinterface/neuropixels_tools.py | 3 ++- src/probeinterface/testing.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/probeinterface/neuropixels_tools.py b/src/probeinterface/neuropixels_tools.py index ed80069e..24722069 100644 --- a/src/probeinterface/neuropixels_tools.py +++ b/src/probeinterface/neuropixels_tools.py @@ -28,7 +28,8 @@ def _load_np_probe_features(): global _np_probe_features if _np_probe_features is None: probe_features_filepath = Path(__file__).absolute().parent / Path("resources/neuropixels_probe_features.json") - _np_probe_features = json.load(open(probe_features_filepath, "r")) + with open(probe_features_filepath, "r") as f: + _np_probe_features = json.load(f) return _np_probe_features diff --git a/src/probeinterface/testing.py b/src/probeinterface/testing.py index 34111dac..f247aceb 100644 --- a/src/probeinterface/testing.py +++ b/src/probeinterface/testing.py @@ -4,7 +4,8 @@ from probeinterface import __version__ as version json_schema_file = Path(__file__).absolute().parent / "schema" / "probe.json.schema" -schema = json.load(open(json_schema_file, "r")) +with open(json_schema_file, "r") as f: + schema = json.load(f) def validate_probe_dict(probe_dict):