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.
 
 
 
 
 
 

44 lines
1.5 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. print_freq = config.get('print_frequency',10)
  21. process_name = config['process_name']
  22. r = redis.Redis(host=redis_address, port=redis_port, decode_responses=True,password=redis_password)
  23. runnings = []
  24. while True:
  25. sims = r.get('Simulations')
  26. sims = json.loads(sims)
  27. for sim in sims:
  28. simulation_id = sim['Id']
  29. process_exists = False
  30. for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
  31. if proc.info['name'] == process_name and len(proc.info['cmdline']) > 1 and proc.info['cmdline'][1] == simulation_id:
  32. process_exists = True
  33. break
  34. if not simulation_id in runnings: #process_exists:
  35. runnings.append(simulation_id)
  36. command = ['./SimulationCore2', redis_address,str(redis_port),redis_password,simulation_id,str(log_level),str(stepTime),str(print_freq)]
  37. print(command)
  38. subprocess.Popen(command, cwd=work_dir)
  39. time.sleep(5)