Skip to content

Commit 037b564

Browse files
committed
[Refactor] Non-daemonic processes in PEnv
ghstack-source-id: c625cd3 Pull-Request: #3225
1 parent 13434eb commit 037b564

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

torchrl/envs/batched_envs.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ class BatchedEnvBase(EnvBase):
196196
one of the environment has dynamic specs.
197197
198198
.. note:: Learn more about dynamic specs and environments :ref:`here <dynamic_envs>`.
199+
daemon (bool, optional): whether the processes should be daemonized.
200+
This is only applicable to parallel environments such as :class:`~torchrl.envs.ParallelEnv`.
201+
Defaults to ``False``.
199202
200203
.. note::
201204
One can pass keyword arguments to each sub-environments using the following
@@ -311,6 +314,7 @@ def __init__(
311314
mp_start_method: str | None = None,
312315
use_buffers: bool | None = None,
313316
consolidate: bool = True,
317+
daemon: bool = False,
314318
):
315319
super().__init__(device=device)
316320
self.serial_for_single = serial_for_single
@@ -320,6 +324,7 @@ def __init__(
320324
self._cache_in_keys = None
321325
self._use_buffers = use_buffers
322326
self.consolidate = consolidate
327+
self.daemon = daemon
323328

324329
self._single_task = callable(create_env_fn) or (len(set(create_env_fn)) == 1)
325330
if callable(create_env_fn):
@@ -1503,7 +1508,7 @@ def look_for_cuda(tensor, has_cuda=has_cuda):
15031508
}
15041509
)
15051510
process = proc_fun(target=func, kwargs=kwargs[idx])
1506-
process.daemon = True
1511+
process.daemon = self.daemon
15071512
process.start()
15081513
child_pipe.close()
15091514
self.parent_channels.append(parent_pipe)

0 commit comments

Comments
 (0)