okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-ds-out ac306afb2 into f-own-intaff3a132f

main
1.1 KiB27 linesraw
1"""Is a program of one of Strata's own folders running (an engine package, a Control bundle, a shape engine)?  Local only.
2
3A folder in use is never removed: on Windows the removal would take its libraries from under the running engine.  (This was
4dsv41_paths.in_use; it never depended on DeepSeek's engine, and every package folder kind uses it.)
5"""
6from __future__ import annotations
7
8import os
9from pathlib import Path
10
11
12def in_use(folder) -> bool:
13    """True when any running process's program or working folder lies in `folder` (psutil; without psutil: False)."""
14    folder = Path(folder)
15    try:
16        import psutil
17    except ImportError:
18        return False
19    here = os.path.normcase(os.path.abspath(folder)) + os.sep
20    for p in psutil.process_iter(["exe", "cwd"]):
21        try:
22            for where in (p.info.get("exe"), p.info.get("cwd")):          # the program, or the folder a Python server runs in (a Control)
23                if where and os.path.normcase(os.path.abspath(where) + os.sep).startswith(here):
24                    return True
25        except (psutil.Error, OSError, ValueError):
26            continue
27    return False