def _worker()

in gym3/subproc.py [0:0]


def _worker(p2c, c2p, decode, env_fn_serialized, env_kwargs_serialized):
    try:
        p2c.close()
        result = None
        err = None
        try:
            env_fn = decode(env_fn_serialized)
            env_kwargs = decode(env_kwargs_serialized)
            env = env_fn(**env_kwargs)
        except Exception as e:
            err = traceback.format_exc()
            c2p.send((result, err))
            return
        else:
            result = (env.ob_space, env.ac_space, env.num)
            c2p.send((result, err))

        while True:
            msg = c2p.recv()
            if msg is None:
                # this is sent to tell the child to exit
                return

            result = None
            try:
                fn = getattr(env, msg["method"])
                result = fn(*msg["args"], **msg["kwargs"])
            except Exception as e:
                err = traceback.format_exc()
            if msg["send_response"]:
                c2p.send((result, err))
            # if send_response is False but an error occurred, the an error will be sent the next time
            # send_response is True
    except KeyboardInterrupt:
        print("Subproc worker: got KeyboardInterrupt")