Skip to content

Commit f773e8d

Browse files
committed
Update
[ghstack-poisoned]
2 parents d6e349d + 22dd9b3 commit f773e8d

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

test/test_env.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3836,6 +3836,8 @@ def test_parallel(self, bwad, use_buffers, maybe_fork_ParallelEnv):
38363836
finally:
38373837
env.close(raise_if_closed=False)
38383838
del env
3839+
time.sleep(0.1)
3840+
gc.collect()
38393841

38403842
class AddString(Transform):
38413843
def __init__(self):

torchrl/envs/batched_envs.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,14 +2489,15 @@ def look_for_cuda(tensor, has_cuda=has_cuda):
24892489
# Make sure the root is updated
24902490
root_shared_tensordict.update_(env._step_mdp(input))
24912491

2492+
# Set event before sending non-tensor data so parent knows worker is done
2493+
# The recv() call itself will provide synchronization for the pipe
2494+
mp_event.set()
2495+
24922496
if _non_tensor_keys:
24932497
child_pipe.send(
24942498
("non_tensor", next_td.select(*_non_tensor_keys, strict=False))
24952499
)
24962500

2497-
# Set event only after non-tensor data is sent to avoid race condition
2498-
mp_event.set()
2499-
25002501
del next_td
25012502

25022503
elif cmd == "step_and_maybe_reset":
@@ -2530,14 +2531,15 @@ def look_for_cuda(tensor, has_cuda=has_cuda):
25302531
event.record()
25312532
event.synchronize()
25322533

2534+
# Set event before sending non-tensor data so parent knows worker is done
2535+
# The recv() call itself will provide synchronization for the pipe
2536+
mp_event.set()
2537+
25332538
if _non_tensor_keys:
25342539
ntd = root_next_td.select(*_non_tensor_keys)
25352540
ntd.set("next", td_next.select(*_non_tensor_keys))
25362541
child_pipe.send(("non_tensor", ntd))
25372542

2538-
# Set event only after non-tensor data is sent to avoid race condition
2539-
mp_event.set()
2540-
25412543
del td, root_next_td
25422544

25432545
elif cmd == "close":

0 commit comments

Comments
 (0)