Simulation Core
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

42 lines
1.4 KiB

  1. import sys
  2. import redis
  3. import json
  4. import time
  5. import subprocess
  6. import psutil
  7. if __name__=='__main__':
  8. if len(sys.argv)<=1:
  9. configFN = 'config-remote.json'
  10. else:
  11. configFN = sys.argv[1]
  12. f = open(configFN)
  13. config = json.load(f)
  14. redis_address = config['redis']['address']
  15. redis_password = config['redis']['password']
  16. redis_port = config['redis']['port']
  17. log_level = config['logging']
  18. work_dir = config['work_dir']
  19. stepTime = config['step_time']
  20. process_name = config['process_name']
  21. r = redis.Redis(host=redis_address, port=redis_port, decode_responses=True,password=redis_password)
  22. runnings = []
  23. while True:
  24. sims = r.get('Simulations')
  25. sims = json.loads(sims)
  26. for sim in sims:
  27. simulation_id = sim['Id']
  28. process_exists = False
  29. for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
  30. if proc.info['name'] == process_name and len(proc.info['cmdline']) > 1 and proc.info['cmdline'][1] == simulation_id:
  31. process_exists = True
  32. break
  33. if not process_exists:
  34. command = ['./SimulationCore2', redis_address,str(redis_port),redis_password,simulation_id,str(log_level),str(stepTime)]
  35. print(command)
  36. subprocess.Popen(command, cwd=work_dir)
  37. time.sleep(5)