Create a new lock object. :param lock_file: path to the file :param timeout: default timeout when acquiring the lock, in seconds. It will be used as fallback value in the acquire method, if no timeout value (``None``) is given. If you want to disable the timeout
( # noqa: PLR0913
self,
lock_file: str | os.PathLike[str],
timeout: float = -1,
mode: int = _UNSET_FILE_MODE,
thread_local: bool = False, # noqa: FBT001, FBT002
*,
blocking: bool = True,
is_singleton: bool = False,
poll_interval: float = 0.05,
lifetime: float | None = None,
loop: asyncio.AbstractEventLoop | None = None,
run_in_executor: bool = True,
executor: futures.Executor | None = None,
)
| 115 | """ |
| 116 | |
| 117 | def __init__( # noqa: PLR0913 |
| 118 | self, |
| 119 | lock_file: str | os.PathLike[str], |
| 120 | timeout: float = -1, |
| 121 | mode: int = _UNSET_FILE_MODE, |
| 122 | thread_local: bool = False, # noqa: FBT001, FBT002 |
| 123 | *, |
| 124 | blocking: bool = True, |
| 125 | is_singleton: bool = False, |
| 126 | poll_interval: float = 0.05, |
| 127 | lifetime: float | None = None, |
| 128 | loop: asyncio.AbstractEventLoop | None = None, |
| 129 | run_in_executor: bool = True, |
| 130 | executor: futures.Executor | None = None, |
| 131 | ) -> None: |
| 132 | """ |
| 133 | Create a new lock object. |
| 134 | |
| 135 | :param lock_file: path to the file |
| 136 | :param timeout: default timeout when acquiring the lock, in seconds. It will be used as fallback value in the |
| 137 | acquire method, if no timeout value (``None``) is given. If you want to disable the timeout, set it to a |
| 138 | negative value. A timeout of 0 means that there is exactly one attempt to acquire the file lock. |
| 139 | :param mode: file permissions for the lockfile. When not specified, the OS controls permissions via umask and |
| 140 | default ACLs, preserving POSIX default ACL inheritance in shared directories. |
| 141 | :param thread_local: Whether this object's internal context should be thread local or not. If this is set to |
| 142 | ``False`` then the lock will be reentrant across threads. When ``True`` (the default), **all fields of the |
| 143 | lock's internal context are per-thread**, including the configuration values ``poll_interval``, ``timeout``, |
| 144 | ``blocking``, ``mode``, and ``lifetime``. Setting one of these properties from one thread does not change |
| 145 | the value seen by another thread; threads that did not perform the write continue to see the value supplied |
| 146 | at construction time. If you need configuration values to be visible across threads, construct the lock |
| 147 | with ``thread_local=False``. |
| 148 | :param blocking: whether the lock should be blocking or not |
| 149 | :param is_singleton: If this is set to ``True`` then only one instance of this class will be created per lock |
| 150 | file. This is useful if you want to use the lock object for reentrant locking without needing to pass the |
| 151 | same object around. |
| 152 | :param poll_interval: default interval for polling the lock file, in seconds. It will be used as fallback value |
| 153 | in the acquire method, if no poll_interval value (``None``) is given. |
| 154 | :param lifetime: maximum time in seconds a lock can be held before it is considered expired. When set, a waiting |
| 155 | process will break a lock whose file modification time is older than ``lifetime`` seconds. ``None`` (the |
| 156 | default) means locks never expire. |
| 157 | :param loop: The event loop to use. If not specified, the running event loop will be used. |
| 158 | :param run_in_executor: If this is set to ``True`` then the lock will be acquired in an executor. |
| 159 | :param executor: The executor to use. If not specified, the default executor will be used. |
| 160 | |
| 161 | """ |
| 162 | self._is_thread_local = thread_local |
| 163 | self._is_singleton = is_singleton |
| 164 | |
| 165 | # Create the context. Note that external code should not work with the context directly and should instead use |
| 166 | # properties of this class. |
| 167 | kwargs: dict[str, Any] = { |
| 168 | "lock_file": os.fspath(lock_file), |
| 169 | "timeout": timeout, |
| 170 | "mode": mode, |
| 171 | "blocking": blocking, |
| 172 | "poll_interval": poll_interval, |
| 173 | "lifetime": lifetime, |
| 174 | "loop": loop, |
nothing calls this directly
no outgoing calls
no test coverage detected