Skip to content

try acquire filelock without blocking (timeout = 0) #64

@awaizman1

Description

@awaizman1

Hi,

It seems that the latest docs (https://filelock.readthedocs.io/en/latest/) is not aligned with the code.
I wanted to try acquire a lock but without blocking if alreadly locked. for this to happen I expected the timeout param to acquire to be equal to 0 (as in many other locking primitives).
The docs says (acquire method of BaseFileLock) that

If timeout <= 0, there is no timeout and this method will block until the lock could be acquired

According to source code (both docstring of BaseFileLock.acquire and method source code) if timeout == 0 the method won't block.
BaseFileLock.acquire docstring:

:arg float timeout:
    The maximum time waited for the file lock.
    If ``timeout < 0``, there is no timeout and this method will
    block until the lock could be acquired.
    If ``timeout`` is None, the default :attr:`~timeout` is used.

BaseFileLock.acquire code:

elif timeout >= 0 and time.time() - start_time > timeout:
    logger().debug('Timeout on acquiring lock %s on %s', lock_id, lock_filename)
        raise Timeout(self._lock_file)

Why latest docs are not aligned - is it just not up-to-date? what needed in order to regenerate it to be aligned.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions