Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions embodichain/lab/sim/sim_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2054,17 +2054,30 @@ def wait_scene_destruction(timeout_ms: int = 10000) -> None:
f"Scene destruction wait timeout, {scene_count} C++ scene(s) still alive!"
)

def destroy(self) -> None:
def destroy(self, exit_process: bool | None = None) -> None:
"""
No longer destructs C++ objects in place due to lingering deep local variables;
instead, packages itself into a destruction task, submits to the cleanup queue,
and waits for top-level delayed consumption.
Comment on lines 2059 to 2061

Args:
exit_process (bool | None): Whether to call os._exit(0) after queuing
the destruction task. If None, reads EMBODICHAIN_SIM_EXIT_PROCESS.
"""
self._is_pending_kill = True

if exit_process is None:
exit_process = (
os.getenv("EMBODICHAIN_SIM_EXIT_PROCESS", "1").strip().lower()
)
exit_process = exit_process not in ("0", "false", "no", "off")
Comment on lines +2068 to +2072

self._is_pending_kill = True
# Transfer the actual destruction logic to the cleanup queue
SimulationManager._cleanup_queue.put(self._deferred_destroy)

if exit_process:
os._exit(0)
Comment on lines +2074 to +2079

def _deferred_destroy(self) -> None:
"""Destroy all simulated assets and release resources."""
# Clean up all gizmos before destroying the simulation
Expand Down
2 changes: 2 additions & 0 deletions scripts/tutorials/gym/random_reach.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@ def _extend_obs(self, obs: EnvObs, **kwargs) -> EnvObs:
print(f"FPS: {fps:.2f}")
else:
print("Elapsed time is too short to calculate FPS.")

env.close()
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import os
import pytest

os.environ.setdefault("EMBODICHAIN_SIM_EXIT_PROCESS", "0")


def pytest_addoption(parser):
parser.addoption(
Expand Down
Loading