run_local_modelverse.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import subprocess
  2. import sys
  3. import os
  4. # sys.executable to use the same Python interpreter used to invoke this command
  5. if len(sys.argv) < 2:
  6. port = "8001"
  7. else:
  8. port = sys.argv[1]
  9. try:
  10. # Compile all SCCD models first
  11. os.chdir("wrappers")
  12. subprocess.check_call([sys.executable, "-m", "sccd.compiler.sccdc", "-p", "threads", "modelverse_SCCD.xml"])
  13. os.chdir("../hybrid_server")
  14. subprocess.check_call([sys.executable, "-m", "sccd.compiler.sccdc", "-p", "threads", "server.xml"])
  15. os.chdir("..")
  16. # Start up all services with auto-detection
  17. import glob
  18. service_paths = glob.glob("services/*/main.py")
  19. services = []
  20. for service_path in service_paths:
  21. print("[SERVICE] loaded " + service_path)
  22. service = subprocess.Popen([sys.executable, service_path, "127.0.0.1:%s" % port])
  23. services.append(service)
  24. sys.path.append("hybrid_server")
  25. sys.path.append(".")
  26. os.chdir("hybrid_server")
  27. #import stacktracer
  28. #stacktracer.trace_start("trace.html",interval=5,auto=True) # Set auto flag to always update file!
  29. import server
  30. import sccd.runtime.socket2event as socket2event
  31. controller = server.Controller([port])
  32. socket2event.boot_translation_service(controller)
  33. controller.start()
  34. except KeyboardInterrupt:
  35. pass
  36. finally:
  37. # Terminate all services as well
  38. for service in services:
  39. try:
  40. service.terminate()
  41. except:
  42. pass