MCPcopy
hub / github.com/pytest-dev/pytest / make_numbered_dir_with_cleanup

Function make_numbered_dir_with_cleanup

src/_pytest/pathlib.py:374–420  ·  src/_pytest/pathlib.py::make_numbered_dir_with_cleanup

Create a numbered dir and register its cleanup. Similar to make_numbered_dir, but also maintains a lock file indicating that the directory is currently in use, and registers the cleanup of the lock and of stale numbered directories. :param keep: The number of sessions to re

(
    *,
    root: Path,
    prefix: str,
    mode: int,
    keep: int,
    lock_timeout: float,
    register: Any,
)

Source from the content-addressed store, hash-verified

372
373
374def make_numbered_dir_with_cleanup(
375 *,
376 root: Path,
377 prefix: str,
378 mode: int,
379 keep: int,
380 lock_timeout: float,
381 register: Any,
382) -> Path:
383 class="st">"""Create a numbered dir and register its cleanup.
384
385 Similar to make_numbered_dir, but also maintains a lock file indicating that
386 the directory is currently in use, and registers the cleanup of the lock and
387 of stale numbered directories.
388
389 :param keep:
390 The number of sessions to retain the directory.
391 :param lock_timeout:
392 In case of a crash, the lock remains class="st">"stuck". The timeout is a time
393 limit after which the lock is considered stale and can be removed.
394 :param register:
395 Called as register(cleanup_func, params...). Should schedule to call
396 passed cleanup functions on session finish.
397 class="st">"""
398 e = None
399 for i in range(10):
400 try:
401 p = make_numbered_dir(root, prefix, mode)
402 class="cm"># Only lock the current dir when keep is not 0
403 if keep != 0:
404 lock_path = create_cleanup_lock(p)
405 register_cleanup_lock_removal(lock_path, register)
406 except Exception as exc:
407 e = exc
408 else:
409 consider_lock_dead_if_created_before = p.stat().st_mtime - lock_timeout
410 class="cm"># Register a cleanup for program exit
411 register(
412 cleanup_numbered_dir,
413 root,
414 prefix,
415 keep,
416 consider_lock_dead_if_created_before,
417 )
418 return p
419 assert e is not None
420 raise e
421
422
423def resolve_from_str(input: str, rootpath: Path) -> Path:

Callers 1

getbasetempMethod · 0.85

Calls 4

make_numbered_dirFunction · 0.85
create_cleanup_lockFunction · 0.85
statMethod · 0.80

Tested by

no test coverage detected