MCPcopy Create free account
hub / github.com/tox-dev/filelock / acquire

Method acquire

src/filelock/_api.py:438–530  ·  view source on GitHub ↗

Try to acquire the file lock. :param timeout: maximum wait time for acquiring the lock, ``None`` means use the default :attr:`~timeout` is and if ``timeout < 0``, there is no timeout and this method will block until the lock could be acquired :param poll_interva

(
        self,
        timeout: float | None = None,
        poll_interval: float | None = None,
        *,
        poll_intervall: float | None = None,
        blocking: bool | None = None,
        cancel_check: Callable[[], bool] | None = None,
    )

Source from the content-addressed store, hash-verified

436 return False
437
438 def acquire(
439 self,
440 timeout: float | None = None,
441 poll_interval: float | None = None,
442 *,
443 poll_intervall: float | None = None,
444 blocking: bool | None = None,
445 cancel_check: Callable[[], bool] | None = None,
446 ) -> AcquireReturnProxy:
447 """
448 Try to acquire the file lock.
449
450 :param timeout: maximum wait time for acquiring the lock, ``None`` means use the default :attr:`~timeout` is and
451 if ``timeout < 0``, there is no timeout and this method will block until the lock could be acquired
452 :param poll_interval: interval of trying to acquire the lock file, ``None`` means use the default
453 :attr:`~poll_interval`
454 :param poll_intervall: deprecated, kept for backwards compatibility, use ``poll_interval`` instead
455 :param blocking: defaults to True. If False, function will return immediately if it cannot obtain a lock on the
456 first attempt. Otherwise, this method will block until the timeout expires or the lock is acquired.
457 :param cancel_check: a callable returning ``True`` when the acquisition should be canceled. Checked on each poll
458 iteration. When triggered, raises :class:`~Timeout` just like an expired timeout.
459
460 :returns: a context object that will unlock the file when the context is exited
461
462 :raises Timeout: if fails to acquire lock within the timeout period
463
464 .. code-block:: python
465
466 # You can use this method in the context manager (recommended)
467 with lock.acquire():
468 pass
469
470 # Or use an equivalent try-finally construct:
471 lock.acquire()
472 try:
473 pass
474 finally:
475 lock.release()
476
477 .. versionchanged:: 2.0.0
478
479 This method returns now a *proxy* object instead of *self*, so that it can be used in a with statement
480 without side effects.
481
482 """
483 # Use the default timeout, if no timeout is provided.
484 if timeout is None:
485 timeout = self._context.timeout
486
487 if blocking is None:
488 blocking = self._context.blocking
489
490 if poll_intervall is not None:
491 msg = "use poll_interval instead of poll_intervall"
492 warnings.warn(msg, DeprecationWarning, stacklevel=2)
493 poll_interval = poll_intervall
494
495 poll_interval = poll_interval if poll_interval is not None else self._context.poll_interval

Calls 2

_poll_until_acquiredMethod · 0.95
AcquireReturnProxyClass · 0.85