Example #1
0
def pyro_expose(c, port, name):
    def stop():
        print('stop() called')
        import os
        os._exit(1)

    from triggerbox import TriggerBox
    tb = TriggerBox(name + ' server on ' + str(port), ['stop server'], [stop])

    c = p4.behavior(instance_mode='single')(c)
    exposed = p4.expose(c)
    p4.Daemon.serveSimple({exposed: name}, ns=False, port=port)

    daemon = p4.Daemon()
    daemon.register(c, name)
    daemon.requestLoop()
Example #2
0
    # one and only
    farmer = farmer_class()

    def refarm():
        global farmer
        del farmer
        farmer = farmer_class()

    stopsimflag = False

    def stopsim():
        global stopsimflag
        print('stopsim called')
        stopsimflag = True

    tb = TriggerBox('Press a button to do something.', ['stop simulation'],
                    [stopsim])

    def playonce(nl, env):
        from multi import fastenv

        # global noise_level
        # env = farmer.acq_env()
        fenv = fastenv(env, 4)
        agent.play(fenv, realtime=False, max_steps=-1, noise_level=nl)
        # epl.rel_env(env)
        env.rel()
        del fenv

    def play_ignore(nl, env):
        import threading as th
        t = th.Thread(target=playonce, args=(nl, env), daemon=True)
Example #3
0
    # noise
    noise_level = hyper.noise_start

    # remote setup
    farmer = None
    def setup_farmer():
        global farmer
        if farmer==None:
            farmer = farmer_class()

    # stop button
    stop_signal = False
    def stop():
        global stop_signal
        stop_signal = True
    stop_button = TriggerBox('Stop Training', ['stop training'], [stop])


    def train_episode(noise_level, env, ac_id):
        try:
            agent.run_episode(env, training=True, render=False, max_steps=-1, noise_level=noise_level, ac_id=ac_id)
        except Exception as ex:
            pass
        if env!=None:
            env.rel()

    def train_if_available(noise_level, ac_id):
        while True:
            remote_env = farmer.acq_env()
            if remote_env == False:
                # no free environment