filelock icon indicating copy to clipboard operation
filelock copied to clipboard

try acquire filelock without blocking (timeout = 0)

Open awaizman1 opened this issue 5 years ago • 1 comments

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!

awaizman1 avatar Apr 02 '20 07:04 awaizman1

Hello, if you make a PR for this (with tests) we would be happy to review it, thanks!

gaborbernat avatar Sep 27 '21 08:09 gaborbernat