MCPcopy Create free account
hub / github.com/pytest-dev/pytest / make_numbered_dir_with_cleanup

Function make_numbered_dir_with_cleanup

src/_pytest/pathlib.py:348–376  ·  view source on GitHub ↗

Create a numbered dir with a cleanup lock and remove old ones.

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

Source from the content-addressed store, hash-verified

346
347
348def make_numbered_dir_with_cleanup(
349 root: Path,
350 prefix: str,
351 keep: int,
352 lock_timeout: float,
353 mode: int,
354) -> Path:
355 """Create a numbered dir with a cleanup lock and remove old ones."""
356 e = None
357 for i in range(10):
358 try:
359 p = make_numbered_dir(root, prefix, mode)
360 lock_path = create_cleanup_lock(p)
361 register_cleanup_lock_removal(lock_path)
362 except Exception as exc:
363 e = exc
364 else:
365 consider_lock_dead_if_created_before = p.stat().st_mtime - lock_timeout
366 # Register a cleanup for program exit
367 atexit.register(
368 cleanup_numbered_dir,
369 root,
370 prefix,
371 keep,
372 consider_lock_dead_if_created_before,
373 )
374 return p
375 assert e is not None
376 raise e
377
378
379def 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
registerMethod · 0.80

Tested by

no test coverage detected