Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

76 lignes
2.5 KiB

  1. import os
  2. import time
  3. import threading
  4. from .logger_utils import setup_global_logging, log_msg as log
  5. from .settings import load_settings
  6. # --- NUOVO IMPORT ---
  7. from .train_executor import run_train_monitor
  8. def build_info() -> str:
  9. return "core-orchestrator-v1.4-background-train"
  10. def run_all_modes(settings):
  11. """Lancia in simultanea i processi core: Collect, Infer e il nuovo Train Executor."""
  12. log("Avvio modalità SIMULTANEA (Collect + Train Executor + Infer)...")
  13. # 1. Importiamo le funzioni dai rispettivi moduli
  14. from .train_collect import run_collect_train
  15. from .infer_mode import run_infer
  16. # 2. Thread per la RACCOLTA DATI (Collect)
  17. t_collect = threading.Thread(target=run_collect_train, args=(settings,), name="CollectorThread", daemon=True)
  18. # 3. Thread per il MONITOR ADDESTRAMENTO (Train Executor)
  19. # Rileva i file .lock inviati dal Web e addestra il modello in background
  20. t_train_exec = threading.Thread(target=run_train_monitor, name="TrainExecutorThread", daemon=True)
  21. # 4. Thread per l'INFERENZA (Predict)
  22. t_infer = threading.Thread(target=run_infer, args=(settings,), name="InferenceThread", daemon=True)
  23. # Avvio di tutti i processi in parallelo
  24. t_collect.start()
  25. t_train_exec.start()
  26. t_infer.start()
  27. log("Tutti i processi core (incluso Train Executor) sono attivi.")
  28. # Mantieni il main process attivo
  29. while True:
  30. time.sleep(10)
  31. def main() -> None:
  32. # Fix percorsi configurazione
  33. if not os.environ.get("CONFIG"):
  34. os.environ["CONFIG"] = "/config/config.yaml"
  35. try:
  36. settings = load_settings()
  37. setup_global_logging(settings)
  38. log(f"Core Orchestrator avviato. BUILD: {build_info()}")
  39. mode = str(settings.get("mode", "all")).strip().lower()
  40. if mode == "all":
  41. run_all_modes(settings)
  42. elif mode == "collect_train":
  43. from .train_collect import run_collect_train
  44. run_collect_train(settings)
  45. elif mode == "infer":
  46. from .infer_mode import run_infer
  47. run_infer(settings)
  48. elif mode == "train":
  49. # Questa rimane la vecchia modalità manuale one-shot
  50. from .train_mode import run_train
  51. run_train(settings)
  52. else:
  53. log(f"Modalità {mode} non riconosciuta.")
  54. except Exception as e:
  55. print(f"ERRORE CRITICO ALL'AVVIO: {e}")
  56. import traceback
  57. traceback.print_exc()
  58. if __name__ == "__main__":
  59. main()