Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Reentrant behavior does not work with distinct lock objects on the same thread #282

Closed
nefrob opened this issue Oct 25, 2023 · 4 comments

Comments

@nefrob
Copy link
Contributor

nefrob commented Oct 25, 2023

Setup

  • Python 3.11.3
  • filelock 3.12.4
  • MacOS

Actual:

python
>>> from filelock import FileLock
>>> lock_1 = FileLock("test.lock")
>>> lock_2 = FileLock("test.lock")
>>> lock_1.acquire()
<filelock._api.AcquireReturnProxy object at 0x100baa550>
>>> lock_1._context
ThreadLocalFileContext(lock_file='test.lock', timeout=-1, mode=420, lock_file_fd=3, lock_counter=1)
>>> lock_2._context
ThreadLocalFileContext(lock_file='test.lock', timeout=-1, mode=420, lock_file_fd=None, lock_counter=0)
>>> lock_2.acquire()
... hangs

Also it does not appear that releasing the lock removes the lock file (not sure if this is expected):

>>> from filelock import FileLock
>>> lock = FileLock("test.lock")
>>> lock.acquire()
<filelock._api.AcquireReturnProxy object at 0x102ad80d0>
>>> lock.release()
➜ ls
test.lock

Expectation:

  • lock_2 can be acquired since it is locking the same file on the same thread per reentrancy definition in docs:

The lock objects are recursive locks, which means that once acquired, they will not block on successive lock requests

(https://py-filelock.readthedocs.io/en/latest/#tutorial)

@nefrob nefrob changed the title Bug: Reentrant behavior does not work with different lock objects on the same thread Bug: Reentrant behavior does not work with distinct lock objects on the same thread Oct 25, 2023
@gaborbernat
Copy link
Member

PR welcome 👍

@nefrob
Copy link
Contributor Author

nefrob commented Oct 27, 2023

Closing this re #283 being merged/released.

@nefrob nefrob closed this as completed Oct 27, 2023
@hmaarrfk
Copy link
Contributor

I'm not sure why this is the expected behavior.

The lock objects lock_1 and lock_2 are just two different objects.

I personally feel like #283 is a step backward.

@gaborbernat
Copy link
Member

It's optional opt in behavior so shouldn't cause you issues 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants