def _subproc_worker(pipe, parent_pipe, env_fn_wrapper, obs_bufs, obs_shapes, obs_dtypes, keys):
def _write_obs(maybe_dict_obs):<EOL><INDENT>flatdict = obs_to_dict(maybe_dict_obs)<EOL>for k in keys:<EOL><INDENT>dst = obs_bufs[k].get_obj()<EOL>dst_np = np.frombuffer(dst, dtype=obs_dtypes[k]).reshape(obs_shapes[k])  <EOL>np.copyto(dst_np, flatdict[k])<EOL><DEDENT><DEDENT>env = env_fn_wrapper.x()<EOL>parent_pipe.close()<EOL>try:<EOL><INDENT>while True:<EOL><INDENT>cmd, data = pipe.recv()<EOL>if cmd == '<STR_LIT>':<EOL><INDENT>pipe.send(_write_obs(env.reset()))<EOL><DEDENT>elif cmd == '<STR_LIT>':<EOL><INDENT>obs, reward, done, info = env.step(data)<EOL>if done:<EOL><INDENT>obs = env.reset()<EOL><DEDENT>pipe.send((_write_obs(obs), reward, done, info))<EOL><DEDENT>elif cmd == '<STR_LIT>':<EOL><INDENT>pipe.send(env.render(mode='<STR_LIT>'))<EOL><DEDENT>elif cmd == '<STR_LIT>':<EOL><INDENT>pipe.send(None)<EOL>break<EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError('<STR_LIT>' % cmd)<EOL><DEDENT><DEDENT><DEDENT>except KeyboardInterrupt:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT>finally:<EOL><INDENT>env.close()<EOL><DEDENT>
Control a single environment instance using IPC and
shared memory.