torchrl.envs.MultiThreadedEnv(*args, _inplace_update=False, _batch_locked=True, **kwargs)[source]

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

>>> 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.


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources