Skip to content

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

@nefrob

Description

@nefrob

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)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions