Simulation Core
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

simulatorManager.py 1.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 simulation_id in runnings: #process_exists:
  34. runnings.append(simulation_id)
  35. command = ['./SimulationCore2', redis_address,str(redis_port),redis_password,simulation_id,str(log_level),str(stepTime)]
  36. print(command)
  37. subprocess.Popen(command, cwd=work_dir)
  38. time.sleep(5)