def launch_simulation(scenario_id): cmd_call = ["python3", "-u", get_script_path(), str(scenario_id), "--extract-data"] threads = request.args.get("threads", None) if threads is not None: cmd_call.extend(["--threads", str(threads)]) proc = Popen(cmd_call, stdout=PIPE, stderr=PIPE, start_new_session=True) entry = SimulationState(scenario_id, proc) state.add(entry) return jsonify(entry.as_dict())
def launch_simulation(scenario_id, threads=None, solver=None): cmd = [ sys.executable, "-u", get_script_path(), str(scenario_id), "--extract-data", ] if threads is not None: cmd.extend(["--threads", str(threads)]) if solver is not None: cmd.extend(["--solver", solver]) new_env = os.environ.copy() new_env["PYTHONPATH"] = str(Path(__file__).parent.parent.parent.absolute()) proc = Popen(cmd, stdout=PIPE, stderr=PIPE, start_new_session=True, env=new_env) entry = SimulationState(scenario_id, proc) state.add(entry) return entry.as_dict()
def test_scenario_state_serializable(test_proc): entry = SimulationState(123, test_proc) keys = entry.as_dict().keys() assert "proc" not in keys assert all(["listener" not in k for k in keys])
def test_scenario_state_refresh(test_proc): entry = SimulationState(123, test_proc) entry.as_dict() assert entry.output == ["foo"] assert entry.errors == []
def test_scenario_state_refresh(test_proc): entry = SimulationState(123, test_proc) time.sleep(0.4) # mitigate race condition entry.as_dict() assert entry.output == ["foo"] assert entry.errors == []