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

Function schedule

tests/conftest.py:159–176  ·  view source on GitHub ↗
(lock: Path, action: Callable[[], None])

Source from the content-addressed store, hash-verified

157def on_break_recheck(mocker: MockerFixture) -> Callable[[Path, Callable[[], None]], None]:
158 # Schedule an action for right after the stale break re-reads the lock file and before it takes the marker.
159 def schedule(lock: Path, action: Callable[[], None]) -> None:
160 lstat = os.lstat
161 state: list[str] = []
162
163 def judged(pid: int) -> bool:
164 # The owner check comes right before the break, whose first look at the path is the recheck.
165 state.append("judged")
166 return process_alive(pid)
167
168 def lstat_then_act(path: str | os.PathLike[str], *, dir_fd: int | None = None) -> os.stat_result:
169 found: Final[os.stat_result] = lstat(path, dir_fd=dir_fd)
170 if state == ["judged"] and os.fspath(path) == os.fspath(lock):
171 state.append("acted")
172 action()
173 return found
174
175 mocker.patch("filelock._identity._process.process_alive", side_effect=judged, autospec=True)
176 mocker.patch.object(os, "lstat", new=lstat_then_act)
177
178 return schedule
179

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected