Virtual coach timeout error


#1

Hi guys,
in order to wait for the sim make_on_status callback to finish, we have the following code, see bellow for full code, here only two lines.

    # wait for sim to be finished
    while sim.get_state() != 'stopped':

is this the best way to do this?
or what is the recommended way?

thanks,
camilo

# The function make_on_status() returns a on_status() function
# This is called a "closure":
# it is here used to pass the sim and datadir objects to on_status()
def make_on_status(sim, datadir):
    def on_status(msg):
        print("Current simulation time: {}".format(msg['simulationTime']))
        if msg['simulationTime'] == 15.0 and sim.get_state() == 'started':
            sim.pause()
            save_position_csv(sim, datadir)
            sim.stop()
            print("Trial terminated - saved CSV in {}".format(datadir))

    return on_status


def run_experiment(datadir, brain_params={'syn_weight': 1.0}):
    #################################################
    # Insert code here:
    # 1) launch the experiment
    # 2) add the status callback
    # 3) add the parametrized brain file
    # 4) add the extra CSV TF
    # 5) start the simulation
    #################################################
    brain_file = brain_template.format(**brain_params)

    sim = vc.launch_experiment('template_manipulation_0')
    sim.register_status_callback(make_on_status(sim, datadir))
    sim.add_transfer_function(record_cylinder_tf)
    sim.edit_brain(brain_file) #solution
    sim.start()
    return sim


tmp_folder = tempfile.mkdtemp()
print('start expe !!!')
sim = run_experiment(datadir=tmp_folder)

# wait for sim to be finished
while sim.get_state() != 'stopped':
    print('waiting...')
    time.sleep(1)

csv_file = os.path.join(tmp_folder, csv_name)
print("Recorded the following csv file: {}".format(csv_file))

@oboder


#2

this approach kind of works, but I don’t know if this is the proper way of doing it.