Support reentrant locking on lock file path via optional singleton instance#283
Support reentrant locking on lock file path via optional singleton instance#283gaborbernat merged 12 commits intotox-dev:mainfrom nefrob:nefrob/reentant-lock-objects
Conversation
|
Downloading pypy locally to investigate test failures. |
gaborbernat
left a comment
There was a problem hiding this comment.
Don't disable ruff checks, address them.
Signed-off-by: Bernát Gábor <[email protected]>
|
Thanks so much for the help! |
|
I think there might be a bug: all derived class of BaseFileLock share the same from filelock import UnixFileLock, BaseFileLock
assert UnixFileLock._instances is BaseFileLock._instancesThis can be resolved by meta class or simpler |
|
BTW, maybe we should check if args like |
|
@YouJiacheng good callout. I think I avoided a metaclass in the first place because Checking mode and timeout don't seem particularly relevant if we determine two singleton locks are the sam object (so will have the same values), unless you meant something else there. |
|
Okay, By checking |
|
@YouJiacheng here is the fix using As for the other question, deciding on how to handle that seems like something for @gaborbernat to decide on. We could:
|
Would be my vote. |
|
Fix for incompatible singleton args: #320. |

Description
Re: #282.
_singleton_per_lock_fileis set instantiating a new lock with the same lock path will return the existing instance of the lock. This means you can reacquire the lock without passing the lock object aroundBased on the
flockdocs (and likely similar for windows/soft cases)(https://man7.org/linux/man-pages/man2/flock.2.html)
a Python solution seems most general and easy here. If anyone has time to dig into different OS file locking mechanisms and see if there is a native solution that would likely be preferable.
Action Items