Nettoyage des processus PDAL orphelins à l'interruption

Ajout de signal handlers (SIGINT/SIGTERM) et atexit pour tuer
les processus pdal orphelins quand le pipeline est interrompu
ou se termine. Utilise pkill -f pdal pour nettoyer.
This commit is contained in:
Antoine Jacquin
2026-05-10 11:58:30 +02:00
parent e73cf75060
commit af8d9c4814

View File

@ -5,6 +5,8 @@ Handles argument parsing, logging configuration, and entry point.
import argparse import argparse
import logging import logging
import os
import signal
import sys import sys
from .pipeline import LidarArchaeoPipeline from .pipeline import LidarArchaeoPipeline
@ -145,6 +147,12 @@ Exemples:
logger.info("Pipeline LiDAR Archéologique") logger.info("Pipeline LiDAR Archéologique")
logger.info("=" * 60) logger.info("=" * 60)
# Kill orphan PDAL processes on interrupt or termination
signal.signal(signal.SIGINT, _kill_orphan_pdal)
signal.signal(signal.SIGTERM, _kill_orphan_pdal)
import atexit
atexit.register(_kill_orphan_pdal)
log_gpu_status() log_gpu_status()
try: try:
@ -191,4 +199,21 @@ Exemples:
pipeline.process_all() pipeline.process_all()
except Exception as e: except Exception as e:
logger.error(f"Erreur fatale: {e}", exc_info=True) logger.error(f"Erreur fatale: {e}", exc_info=True)
sys.exit(1) sys.exit(1)
def _kill_orphan_pdal(signum=None, frame=None):
"""Kill orphan PDAL processes on interrupt or exit."""
import subprocess
try:
subprocess.run(["pkill", "-f", "pdal"], capture_output=True, timeout=5)
except Exception:
pass
if signum is not None:
logger.info("Interruption — nettoyage des processus PDAL")
sys.exit(130)
def main():
"""Entry point for the LiDAR archaeological pipeline."""
parser = argparse.ArgumentParser(