コード例 #1
0
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())
コード例 #2
0
def test_app_state_get(test_proc):
    state = ApplicationState()
    assert len(state.ongoing) == 0

    entry = SimulationState(123, test_proc)
    state.add(entry)
    assert len(state.ongoing) == 1
    assert state.get(123) is not None
コード例 #3
0
ファイル: app.py プロジェクト: Breakthrough-Energy/REISE.jl
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()
コード例 #4
0
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])
コード例 #5
0
def test_scenario_state_refresh(test_proc):
    entry = SimulationState(123, test_proc)
    entry.as_dict()
    assert entry.output == ["foo"]
    assert entry.errors == []
コード例 #6
0
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 == []