Skip to content

Commit dc25a55

Browse files
author
Vincent Moens
committed
[BugFix,Doc] Fix BATCHED_PIPE_TIMEOUT refs and doc
ghstack-source-id: 6e43c4f Pull Request resolved: #2695
1 parent 4b3279a commit dc25a55

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

torchrl/envs/batched_envs.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,10 @@ class ParallelEnv(BatchedEnvBase, metaclass=_PEnvMeta):
12171217
__doc__ += BatchedEnvBase.__doc__
12181218
__doc__ += """
12191219
1220+
.. note:: ParallelEnv will timeout after one of the worker is idle for a determinate amount of time.
1221+
This can be controlled via the BATCHED_PIPE_TIMEOUT environment variable, which in turn modifies
1222+
the torchrl._utils.BATCHED_PIPE_TIMEOUT integer. The default timeout value is 10000 seconds.
1223+
12201224
.. warning::
12211225
TorchRL's ParallelEnv is quite stringent when it comes to env specs, since
12221226
these are used to build shared memory buffers for inter-process communication.
@@ -1353,7 +1357,10 @@ class ParallelEnv(BatchedEnvBase, metaclass=_PEnvMeta):
13531357
"""
13541358

13551359
def _start_workers(self) -> None:
1360+
import torchrl
1361+
13561362
self._timeout = 10.0
1363+
self.BATCHED_PIPE_TIMEOUT = torchrl._utils.BATCHED_PIPE_TIMEOUT
13571364

13581365
from torchrl.envs.env_creator import EnvCreator
13591366

@@ -1606,7 +1613,7 @@ def step_and_maybe_reset(
16061613

16071614
for i in workers_range:
16081615
event = self._events[i]
1609-
event.wait(self._timeout)
1616+
event.wait(self.BATCHED_PIPE_TIMEOUT)
16101617
event.clear()
16111618

16121619
if self._non_tensor_keys:
@@ -1796,7 +1803,7 @@ def _step(self, tensordict: TensorDictBase) -> TensorDictBase:
17961803

17971804
for i in workers_range:
17981805
event = self._events[i]
1799-
event.wait(self._timeout)
1806+
event.wait(self.BATCHED_PIPE_TIMEOUT)
18001807
event.clear()
18011808

18021809
if self._non_tensor_keys:
@@ -1965,7 +1972,7 @@ def tentative_update(val, other):
19651972

19661973
for i, _ in outs:
19671974
event = self._events[i]
1968-
event.wait(self._timeout)
1975+
event.wait(self.BATCHED_PIPE_TIMEOUT)
19691976
event.clear()
19701977

19711978
workers_nontensor = []
@@ -2023,7 +2030,7 @@ def _shutdown_workers(self) -> None:
20232030
for channel in self.parent_channels:
20242031
channel.close()
20252032
for proc in self._workers:
2026-
proc.join(timeout=1.0)
2033+
proc.join(timeout=self._timeout)
20272034
finally:
20282035
for proc in self._workers:
20292036
if proc.is_alive():

0 commit comments

Comments
 (0)