feat(_internal): Add typed, asyncio-friendly file locking module - #501
feat(_internal): Add typed, asyncio-friendly file locking module#501tony wants to merge 4 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #501 +/- ##
==========================================
+ Coverage 58.23% 59.98% +1.74%
==========================================
Files 40 42 +2
Lines 6489 6930 +441
Branches 1098 1130 +32
==========================================
+ Hits 3779 4157 +378
- Misses 2177 2235 +58
- Partials 533 538 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…module why: Enable safe concurrent access to shared resources across multiple processes, particularly for pytest-xdist parallel test execution. what: - Add FileLock class with context manager support - Add atomic_init() for one-time initialization with locking - Support both sync and async usage patterns - Use fcntl for Unix file locking
what: - Add FileLock context manager tests - Add atomic_init race condition tests - Add timeout and error handling tests - Add multi-process locking tests
what: - Add docs/internals/file_lock.md with API reference - Add file_lock to internals toctree
|
Automated review finding. Recorded here so it is not lost. Nothing has been pushed to this branch and no fix is applied — this is a note, not a change request. Stale-lock removal is time-based only, never checks whether the holder is alive
Failure scenario: process A legitimately holds the lock for longer than Suggested fix: before removing, confirm the recorded PID is actually gone: try:
os.kill(pid, 0)
except ProcessLookupError:
pass # holder is gone; safe to reclaim
else:
return # holder is alive; not staleNote: |
Summary
FileLockclass for cross-platform file locking with context manager supportatomic_initfunction for race-free initialization (useful with pytest-xdist)Test plan