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

Method __init__

src/filelock/asyncio.py:104–152  ·  view source on GitHub ↗

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 timeo

(  # noqa: PLR0913
        self,
        lock_file: str | os.PathLike[str],
        timeout: float = -1,
        mode: int = 0o644,
        thread_local: bool = False,  # noqa: FBT001, FBT002
        *,
        blocking: bool = True,
        is_singleton: bool = False,
        loop: asyncio.AbstractEventLoop | None = None,
        run_in_executor: bool = True,
        executor: futures.Executor | None = None,
    )

Source from the content-addressed store, hash-verified

102 """Base class for asynchronous file locks."""
103
104 def __init__( # noqa: PLR0913
105 self,
106 lock_file: str | os.PathLike[str],
107 timeout: float = -1,
108 mode: int = 0o644,
109 thread_local: bool = False, # noqa: FBT001, FBT002
110 *,
111 blocking: bool = True,
112 is_singleton: bool = False,
113 loop: asyncio.AbstractEventLoop | None = None,
114 run_in_executor: bool = True,
115 executor: futures.Executor | None = None,
116 ) -> None:
117 """
118 Create a new lock object.
119
120 :param lock_file: path to the file
121 :param timeout: default timeout when acquiring the lock, in seconds. It will be used as fallback value in \
122 the acquire method, if no timeout value (``None``) is given. If you want to disable the timeout, set it \
123 to a negative value. A timeout of 0 means that there is exactly one attempt to acquire the file lock.
124 :param mode: file permissions for the lockfile
125 :param thread_local: Whether this object's internal context should be thread local or not. If this is set to \
126 ``False`` then the lock will be reentrant across threads.
127 :param blocking: whether the lock should be blocking or not
128 :param is_singleton: If this is set to ``True`` then only one instance of this class will be created \
129 per lock file. This is useful if you want to use the lock object for reentrant locking without needing \
130 to pass the same object around.
131 :param loop: The event loop to use. If not specified, the running event loop will be used.
132 :param run_in_executor: If this is set to ``True`` then the lock will be acquired in an executor.
133 :param executor: The executor to use. If not specified, the default executor will be used.
134
135 """
136 self._is_thread_local = thread_local
137 self._is_singleton = is_singleton
138
139 # Create the context. Note that external code should not work with the context directly and should instead use
140 # properties of this class.
141 kwargs: dict[str, Any] = {
142 "lock_file": os.fspath(lock_file),
143 "timeout": timeout,
144 "mode": mode,
145 "blocking": blocking,
146 "loop": loop,
147 "run_in_executor": run_in_executor,
148 "executor": executor,
149 }
150 self._context: AsyncFileLockContext = (AsyncThreadLocalFileContext if thread_local else AsyncFileLockContext)(
151 **kwargs
152 )
153
154 @property
155 def run_in_executor(self) -> bool:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected