v1.0 - Version stable: multi-PC, détection UI-DETR-1, 3 modes exécution
- Frontend v4 accessible sur réseau local (192.168.1.40) - Ports ouverts: 3002 (frontend), 5001 (backend), 5004 (dashboard) - Ollama GPU fonctionnel - Self-healing interactif - Dashboard confiance Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
192
scripts/start_vwb_backend_thread_safe.py
Normal file
192
scripts/start_vwb_backend_thread_safe.py
Normal file
@@ -0,0 +1,192 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Script de démarrage du backend VWB avec solution thread-safe.
|
||||
|
||||
Auteur : Dom, Alice, Kiro - 09 janvier 2026
|
||||
|
||||
Ce script démarre le backend VWB avec la solution thread-safe pour
|
||||
la capture d'écran, résolvant les problèmes de threading avec Flask.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import time
|
||||
import requests
|
||||
from pathlib import Path
|
||||
|
||||
def check_dependencies():
|
||||
"""Vérifie que les dépendances sont disponibles."""
|
||||
print("🔍 Vérification des dépendances...")
|
||||
|
||||
root_dir = Path(__file__).parent.parent
|
||||
venv_python = root_dir / "venv_v3" / "bin" / "python3"
|
||||
|
||||
if not venv_python.exists():
|
||||
print("❌ Environnement virtuel venv_v3 non trouvé")
|
||||
return False
|
||||
|
||||
# Test des imports critiques
|
||||
test_script = """
|
||||
try:
|
||||
import mss
|
||||
print("✅ mss disponible")
|
||||
except ImportError:
|
||||
print("❌ mss non disponible")
|
||||
|
||||
try:
|
||||
import torch
|
||||
print("✅ torch disponible")
|
||||
except ImportError:
|
||||
print("❌ torch non disponible")
|
||||
|
||||
try:
|
||||
import open_clip
|
||||
print("✅ open_clip disponible")
|
||||
except ImportError:
|
||||
print("❌ open_clip non disponible")
|
||||
|
||||
try:
|
||||
import flask
|
||||
print("✅ flask disponible")
|
||||
except ImportError:
|
||||
print("❌ flask non disponible")
|
||||
"""
|
||||
|
||||
try:
|
||||
result = subprocess.run([
|
||||
str(venv_python), "-c", test_script
|
||||
], capture_output=True, text=True, timeout=30)
|
||||
|
||||
print(result.stdout)
|
||||
|
||||
if "❌" in result.stdout:
|
||||
print("⚠️ Certaines dépendances manquent")
|
||||
return False
|
||||
|
||||
print("✅ Toutes les dépendances sont disponibles")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Erreur lors de la vérification: {e}")
|
||||
return False
|
||||
|
||||
def start_backend_server(port=5002):
|
||||
"""Démarre le serveur backend avec la solution thread-safe."""
|
||||
print(f"🚀 Démarrage du backend VWB thread-safe sur le port {port}...")
|
||||
|
||||
root_dir = Path(__file__).parent.parent
|
||||
venv_python = root_dir / "venv_v3" / "bin" / "python3"
|
||||
backend_script = root_dir / "visual_workflow_builder" / "backend" / "app_lightweight.py"
|
||||
|
||||
# Variables d'environnement
|
||||
env = os.environ.copy()
|
||||
env['PYTHONPATH'] = str(root_dir)
|
||||
env['PORT'] = str(port)
|
||||
env['FLASK_ENV'] = 'development'
|
||||
|
||||
print(f"🐍 Python: {venv_python}")
|
||||
print(f"📁 Script: {backend_script}")
|
||||
print(f"🌐 Port: {port}")
|
||||
print(f"🔧 Solution: Thread-safe screen capture")
|
||||
print("")
|
||||
|
||||
try:
|
||||
# Démarrer le serveur
|
||||
process = subprocess.Popen([
|
||||
str(venv_python),
|
||||
str(backend_script)
|
||||
], env=env, cwd=str(root_dir))
|
||||
|
||||
# Attendre que le serveur démarre
|
||||
print("⏳ Attente du démarrage du serveur...")
|
||||
if wait_for_server(port):
|
||||
print(f"✅ Serveur démarré avec succès !")
|
||||
print(f"🌐 URL: http://localhost:{port}")
|
||||
print(f"❤️ Health: http://localhost:{port}/health")
|
||||
print(f"📷 Capture: http://localhost:{port}/api/screen-capture")
|
||||
print(f"🎯 Embedding: http://localhost:{port}/api/visual-embedding")
|
||||
print("")
|
||||
print("Appuyez sur Ctrl+C pour arrêter")
|
||||
|
||||
# Attendre l'arrêt
|
||||
process.wait()
|
||||
else:
|
||||
print("❌ Timeout - serveur non démarré")
|
||||
process.terminate()
|
||||
return False
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\n🛑 Arrêt du serveur...")
|
||||
process.terminate()
|
||||
process.wait()
|
||||
except Exception as e:
|
||||
print(f"❌ Erreur: {e}")
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def wait_for_server(port, timeout=30):
|
||||
"""Attend que le serveur soit prêt."""
|
||||
start_time = time.time()
|
||||
while time.time() - start_time < timeout:
|
||||
try:
|
||||
response = requests.get(f"http://localhost:{port}/health", timeout=2)
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
if data.get('features', {}).get('screen_capture'):
|
||||
return True
|
||||
except:
|
||||
pass
|
||||
time.sleep(1)
|
||||
return False
|
||||
|
||||
def test_capture_functionality(port=5002):
|
||||
"""Teste rapidement la fonctionnalité de capture."""
|
||||
print("🧪 Test rapide de la capture d'écran...")
|
||||
|
||||
try:
|
||||
response = requests.post(
|
||||
f"http://localhost:{port}/api/screen-capture",
|
||||
json={"format": "png", "quality": 90},
|
||||
timeout=15
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
if data.get('success'):
|
||||
print(f"✅ Test réussi - {data['width']}x{data['height']}")
|
||||
return True
|
||||
else:
|
||||
print(f"❌ Test échoué: {data.get('error', 'inconnue')}")
|
||||
return False
|
||||
else:
|
||||
print(f"❌ Erreur HTTP: {response.status_code}")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Erreur test: {e}")
|
||||
return False
|
||||
|
||||
def main():
|
||||
"""Fonction principale."""
|
||||
print("=" * 60)
|
||||
print(" BACKEND VWB - DÉMARRAGE THREAD-SAFE")
|
||||
print("=" * 60)
|
||||
print("Auteur : Dom, Alice, Kiro - 09 janvier 2026")
|
||||
print("")
|
||||
|
||||
# Vérifier les dépendances
|
||||
if not check_dependencies():
|
||||
print("❌ Dépendances manquantes - arrêt")
|
||||
return False
|
||||
|
||||
# Déterminer le port
|
||||
port = int(os.getenv('PORT', 5002))
|
||||
|
||||
# Démarrer le serveur
|
||||
return start_backend_server(port)
|
||||
|
||||
if __name__ == '__main__':
|
||||
success = main()
|
||||
sys.exit(0 if success else 1)
|
||||
Reference in New Issue
Block a user