Why this change is needed:
The CI pipeline was failing on the "Run pre-commit" step with 6 F841
errors (unused variables) and 1 formatting issue (missing trailing comma).
This was blocking the PR from being merged.
How it solves it:
1. Added trailing comma to _get_workspace_lock() function signature
to match Python formatting standards
2. Changed unused lock variables (lock1, lock2) to underscore (_)
in test_finalization_cleanup.py to indicate intentional disposal
of return values (locks are created for their side effects only)
3. Applied ruff-format auto-formatting fixes
Impact:
- All pre-commit checks now pass locally
- CI pipeline should pass on next push
- No functional changes, only code style fixes
Testing:
Verified with: uv run pre-commit run --files <modified files>
All checks passed: trailing whitespace, end of files, ruff-format, ruff
Why this change is needed:
The finalize_share_data() function was not properly cleaning up workspace
lock-related global variables (_sync_locks, _workspace_async_locks, and
lock registry variables). This caused stale references to remain after
finalization, leading to EOFError or BrokenPipeError when trying to
re-initialize or when processes tried to use locks after the Manager
was shut down.
How it solves it:
1. Added comprehensive cleanup of all Manager.dict proxies before Manager
shutdown (_sync_locks, _lock_registry, _lock_registry_count,
_lock_cleanup_data)
2. Added cleanup of per-process _workspace_async_locks dictionary
3. Reset all lock-related globals to None at end of finalization:
- _workers, _lock_registry, _lock_registry_count, _lock_cleanup_data
- _registry_guard, _storage_keyed_lock, _sync_locks
- _workspace_async_locks, _earliest_mp_cleanup_time,
_last_mp_cleanup_time
Impact:
- Prevents EOFError/BrokenPipeError in production deployments
- Enables safe re-initialization after finalization
- Critical for proper resource cleanup in multi-process deployments
- Fixes memory leaks from stale lock references
Testing:
- Added 3 comprehensive tests in test_finalization_cleanup.py
- All 23 workspace lock tests pass (17 original + 3 bug fixes + 3 finalization)
- Tests verify clean re-initialization after finalization in both
single-process and multiprocess modes