fix(python): add collection close method#567
Conversation
|
Thanks for putting together this PR. |
Close() flushes and releases segments, managers, and the collection file lock even while other references to the handle remain alive. Post-close operations are rejected with "collection is already closed" instead of touching released state, and closing twice is a no-op. Python Collection.close() now calls the native Close() before dropping its references.
|
Thanks for the review — agreed. Dropping the Python reference only decrements a refcount, so it gives no guarantee when other references, shallow copies, or in-flight operations keep the object alive. I've reworked the PR to expose an explicit native
While rerunning the suite I also noticed One note on scope: the C API's Testing: |
Summary
Closes #563.
Adds
Collection.close()to release the Python wrapper's underlying_Collectionhandle, so callers can explicitly drop native resources before reopening or removing a collection path. The concurrent-open test now records the opened path before closing the worker handle.Note: I used Codex to help prepare this change, reviewed the final diff, and ran the listed checks locally.
Testing
git submodule update --init --recursive --depth=1python3 -m venv .venv.venv/bin/python -m pip install --upgrade pip setuptools wheel.venv/bin/python -m pip install -e ".[test]".venv/bin/python -m pytest python/tests/detail/test_collection_open.py::TestCollectionOpen::test_close_releases_collection_for_reopen -q.venv/bin/python -m pytest python/tests/detail/test_collection_open.py -q.venv/bin/python -m compileall -q python/zvec/model/collection.py python/tests/detail/test_collection_open.py.venv/bin/python -m pip install "ruff>=0.4".venv/bin/python -m ruff check python/zvec/model/collection.py python/tests/detail/test_collection_open.pygit diff --check