- torchrl.envs.MultiThreadedEnv(*args, _inplace_update=False, _batch_locked=True, **kwargs)¶
Multithreaded execution of environments based on EnvPool.
An alternative to ParallelEnv based on multithreading. It’s faster, as it doesn’t require new process spawning, but less flexible, as it only supports environments implemented in EnvPool library. Currently only supports synchronous execution mode, when the batch size is equal to the number of workers, see https://envpool.readthedocs.io/en/latest/content/python_interface.html#batch-size.
>>> env = MultiThreadedEnv(num_workers=3, env_name="Pendulum-v1") >>> env.reset() >>> env.rand_step() >>> env.rollout(5) >>> env.close()
num_workers – number of worker threads to create.
env_name – name of the environment, corresponding to task_id in EnvPool.
create_env_kwargs – additional arguments which will be passed to envpool.make.