|
- import sys
- import redis
- import json
- import time
- import subprocess
- import psutil
-
- if __name__=='__main__':
- if len(sys.argv)<=1:
- configFN = 'config-remote.json'
- else:
- configFN = sys.argv[1]
-
- f = open(configFN)
- config = json.load(f)
-
- redis_address = config['redis']['address']
- redis_password = config['redis']['password']
- redis_port = config['redis']['port']
- log_level = config['logging']
- work_dir = config['work_dir']
- stepTime = config['step_time']
- print_freq = config.get('print_frequency',10)
- process_name = config['process_name']
-
- r = redis.Redis(host=redis_address, port=redis_port, decode_responses=True,password=redis_password)
- runnings = []
- while True:
- sims = r.get('Simulations')
- sims = json.loads(sims)
- for sim in sims:
- simulation_id = sim['Id']
- process_exists = False
- for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
- if proc.info['name'] == process_name and len(proc.info['cmdline']) > 1 and proc.info['cmdline'][1] == simulation_id:
- process_exists = True
- break
- if not simulation_id in runnings: #process_exists:
- runnings.append(simulation_id)
- command = ['./SimulationCore2', redis_address,str(redis_port),redis_password,simulation_id,str(log_level),str(stepTime),str(print_freq)]
- print(command)
- subprocess.Popen(command, cwd=work_dir)
- time.sleep(5)
|