Borner le nettoyage PDAL à notre run et supprimer le pkill à chaque sortie

This commit is contained in:
Antoine Jacquin
2026-09-18 21:09:32 +02:00
parent bb086e308a
commit ecd21d5b46

View File

@ -15,6 +15,10 @@ from .gpu import log_gpu_status
logger = logging.getLogger("lidar") logger = logging.getLogger("lidar")
# Motif pkill des processus PDAL de CE run (renseigné dans main) — cf.
# _kill_orphan_pdal : borné à notre output pour épargner les autres runs.
_pdal_kill_pattern = None
def setup_logging(verbose=False, debug=False): def setup_logging(verbose=False, debug=False):
"""Configure the 'lidar' logger. """Configure the 'lidar' logger.
@ -273,11 +277,15 @@ def main():
from .gpu import restrict_gpus from .gpu import restrict_gpus
restrict_gpus(gpu_ids) restrict_gpus(gpu_ids)
# Kill orphan PDAL processes on interrupt or termination # Kill orphan PDAL processes on interrupt or termination. Le motif est
# borné à NOTRE répertoire temporaire (pdal pipeline <output>/temp/…) : un
# pkill global massacrerient les PDAL des autres runs de la machine (ex.
# job webapp concurrent). Pas de hook atexit : une sortie normale n'a
# aucune raison de tuer quoi que ce soit.
global _pdal_kill_pattern
_pdal_kill_pattern = f"pdal pipeline {args.output}/temp/"
signal.signal(signal.SIGINT, _kill_orphan_pdal) signal.signal(signal.SIGINT, _kill_orphan_pdal)
signal.signal(signal.SIGTERM, _kill_orphan_pdal) signal.signal(signal.SIGTERM, _kill_orphan_pdal)
import atexit
atexit.register(_kill_orphan_pdal)
log_gpu_status() log_gpu_status()
@ -394,14 +402,19 @@ def main():
def _kill_orphan_pdal(signum=None, frame=None): def _kill_orphan_pdal(signum=None, frame=None):
"""Kill orphan PDAL processes on interrupt or exit.""" """Kill orphan PDAL processes of THIS run on interrupt or termination."""
import subprocess import subprocess
# Belt-and-suspenders: os.killpg below is the primary mechanism. # Belt-and-suspenders: os.killpg below is the primary mechanism.
# This handles the edge case where a child escapes the process group. # This handles the edge case where a child escapes the process group.
try: # Motif borné à notre output (cf. main) pour ne pas tuer les PDAL des
subprocess.run(["pkill", "-9", "-f", "pdal pipeline"], capture_output=True, timeout=3) # autres runs de la machine.
except Exception: if _pdal_kill_pattern:
pass try:
import re
subprocess.run(["pkill", "-9", "-f", re.escape(_pdal_kill_pattern)],
capture_output=True, timeout=3)
except Exception:
pass
if signum is not None: if signum is not None:
logger.info("Interruption — nettoyage des processus") logger.info("Interruption — nettoyage des processus")
# Force-kill all child processes immediately # Force-kill all child processes immediately