run_local_modelverse.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. os.chdir("hybrid_server")
  25. program_to_execute = [sys.executable, "run_mvk_server.py", port]
  26. server = subprocess.Popen(program_to_execute)
  27. server.wait()
  28. finally:
  29. # Stop the server
  30. try:
  31. server.terminate()
  32. except:
  33. pass
  34. # Terminate all services as well
  35. for service in services:
  36. try:
  37. service.terminate()
  38. except:
  39. pass