Exemple #1
0
def start_job(job_id: int) -> subprocess.Popen:
    job = Job.query.get_or_404(job_id)
    driver, series, label, config = job.driver, job.series, job.label, job.config

    # Create a directory for the simulation
    sim = Simulation(series, label)
    simdir = sim.simdir()
    try:
        os.mkdir(simdir)
    except PermissionError as e:
        raise e  # TODO
    except FileExistsError as e:
        raise SimulationAlreadyExistsError(series, label, driver)

    # Put the uploaded config file there
    saveto = sim.config_fn()
    if os.path.exists(saveto):
        raise SimulationAlreadyExistsError(series, label, driver)

    with open(saveto, "w") as fp:
        fp.write(config)
        logging.info(f"Saved config file to {saveto}")

    # Queue the simulation
    executable = os.path.join(DPMDIR, driver)
    stdout_f = open(sim.out_fn(), "a")
    stderr_f = open(sim.err_fn(), "a")
    command = [executable, saveto, "-name", label]

    print(command)
    subp = subprocess.Popen(['echo'] + command,
                            cwd=simdir,
                            stdout=stdout_f,
                            stderr=stderr_f)

    job.status = 1
    db.session.commit()

    return subp
Exemple #2
0
def showlogerr(sername, simname):
    sim = Simulation(sername, simname)
    with open(sim.err_fn(), "r") as err_f:
        return Response(err_f.read(), mimetype="text/plain")