_error.py 787 B

123456789101112131415161718192021222324252627282930
  1. from __future__ import annotations
  2. from typing import Any
  3. class Timeout(TimeoutError): # noqa: N818
  4. """Raised when the lock could not be acquired in *timeout* seconds."""
  5. def __init__(self, lock_file: str) -> None:
  6. super().__init__()
  7. self._lock_file = lock_file
  8. def __reduce__(self) -> str | tuple[Any, ...]:
  9. return self.__class__, (self._lock_file,) # Properly pickle the exception
  10. def __str__(self) -> str:
  11. return f"The file lock '{self._lock_file}' could not be acquired."
  12. def __repr__(self) -> str:
  13. return f"{self.__class__.__name__}({self.lock_file!r})"
  14. @property
  15. def lock_file(self) -> str:
  16. """:return: The path of the file lock."""
  17. return self._lock_file
  18. __all__ = [
  19. "Timeout",
  20. ]