(job)
This fn runs in a new process.  Now we are going to do a little
    bookkeeping and then spin off the actual job that does whatever it is we're
    trying to achieve.
This fn runs in a new process.  Now we are going to do a little
    bookkeeping and then spin off the actual job that does whatever it is we're
    trying to achieve.
This fn runs in a new process . Now we are going to do a little bookkeeping and then spin off the actual job that does whatever it is we re trying to achieve .
def job_runner(job):
    '''This fn runs in a new process.  Now we are going to do a little
    bookkeeping and then spin off the actual job that does whatever it is we're
    trying to achieve.'''

    redirect_output(job_output_file(job))
    log("Running in wrapper mode for '%s'\n" % (job.id))

    ExperimentGrid.job_running(job.expt_dir, job.id)

    # Update metadata and save the job file, which will be read by the job wrappers.
    job.start_t = int(time.time())
    job.status  = 'running'
    save_job(job)

    success    = False
    start_time = time.time()

    try:
        if job.language == MATLAB:   run_matlab_job(job)
        elif job.language == PYTHON: run_python_job(job)
        elif job.language == SHELL:  run_torch_job(job)
        elif job.language == MCR:    run_mcr_job(job)
        else:
            raise Exception("That function type has not been implemented.")

        success = True
    except:
        log("-" * 40)
        log("Problem running the job:")
        log(sys.exc_info())
        log(traceback.print_exc(limit=1000))
        log("-" * 40)

    end_time = time.time()
    duration = end_time - start_time

    # The job output is written back to the job file, so we read it back in to
    # get the results.
    job_file = job_file_for(job)
    job      = load_job(job_file)

    log("Job file reloaded.")

    if not job.HasField("value"):
        log("Could not find value in output file.")
        success = False

    if success:
        log("Completed successfully in %0.2f seconds. [%f]"
                         % (duration, job.value))

        # Update the status for this job.
        ExperimentGrid.job_complete(job.expt_dir, job.id,
                                    job.value, duration)
        job.status = 'complete'
    else:
        log("Job failed in %0.2f seconds." % (duration))

        # Update the experiment status for this job.
        ExperimentGrid.job_broken(job.expt_dir, job.id)
        job.status = 'broken'

    job.end_t    = int(time.time())
    job.duration = duration

    save_job(job)
def job_runner ( job ) : redirect_output ( job_output_file ( job ) ) log ( "Running in wrapper mode for '%s'\n" % ( job . id ) ) ExperimentGrid . job_running ( job . expt_dir , job . id ) # Update metadata and save the job file, which will be read by the job wrappers. job . start_t = int ( time . time ( ) ) job . status = 'running' save_job ( job ) success = False start_time = time . time ( ) try : if job . language == MATLAB : run_matlab_job ( job ) elif job . language == PYTHON : run_python_job ( job ) elif job . language == SHELL : run_torch_job ( job ) elif job . language == MCR : run_mcr_job ( job ) else : raise Exception ( "That function type has not been implemented." ) success = True except : log ( "-" * 40 ) log ( "Problem running the job:" ) log ( sys . exc_info ( ) ) log ( traceback . print_exc ( limit = 1000 ) ) log ( "-" * 40 ) end_time = time . time ( ) duration = end_time - start_time # The job output is written back to the job file, so we read it back in to # get the results. job_file = job_file_for ( job ) job = load_job ( job_file ) log ( "Job file reloaded." ) if not job . HasField ( "value" ) : log ( "Could not find value in output file." ) success = False if success : log ( "Completed successfully in %0.2f seconds. [%f]" % ( duration , job . value ) ) # Update the status for this job. ExperimentGrid . job_complete ( job . expt_dir , job . id , job . value , duration ) job . status = 'complete' else : log ( "Job failed in %0.2f seconds." % ( duration ) ) # Update the experiment status for this job. ExperimentGrid . job_broken ( job . expt_dir , job . id ) job . status = 'broken' job . end_t = int ( time . time ( ) ) job . duration = duration save_job ( job )