Skip to content
Empty file.
55 changes: 55 additions & 0 deletions source/isaaclab/test/app/_standalone_kit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md).
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause

"""Run Kit smoke-test children without globally flushing background workers' native files."""

import ctypes
import os
import runpy
import sys
from pathlib import Path


def flush_stdio() -> None:
"""Flush Python and native stdout/stderr before Kit's fast shutdown exits the process.

Flushing every C stream with ``fflush(NULL)`` can wait forever for a file lock held by a
background thread. Only the two standard output streams need flushing before ``_exit``.
"""
for stream in (sys.stdout, sys.stderr):
try:
stream.flush()
except (ValueError, OSError, AttributeError):
pass
try:
libc = ctypes.CDLL("ucrtbase" if os.name == "nt" else None)
libc.fflush.argtypes = [ctypes.c_void_p]
libc.fflush.restype = ctypes.c_int
if os.name == "nt":
libc.__acrt_iob_func.argtypes = [ctypes.c_uint]
libc.__acrt_iob_func.restype = ctypes.c_void_p
streams = (libc.__acrt_iob_func(1), libc.__acrt_iob_func(2))
else:
names = ("__stdoutp", "__stderrp") if sys.platform == "darwin" else ("stdout", "stderr")
streams = tuple(ctypes.c_void_p.in_dll(libc, name) for name in names)
for stream in streams:
libc.fflush(stream)
except (ImportError, OSError, AttributeError, TypeError, ValueError):
pass


if __name__ == "__main__":
from isaacsim.simulation_app import SimulationApp

# Isaac Sim 6.3's fflush(NULL) can block on an unrelated background stream lock.
# Limit this workaround to the smoke-test child; normal Kit cleanup still runs.
SimulationApp._flush_stdio = staticmethod(flush_stdio)
sys.argv.pop(0)
if sys.argv[0] == "-m":
sys.argv.pop(0)
runpy.run_module(sys.argv[0], run_name="__main__", alter_sys=True)
else:
sys.path[0] = str(Path(sys.argv[0]).resolve().parent)
runpy.run_path(sys.argv[0], run_name="__main__")
2 changes: 2 additions & 0 deletions source/isaaclab/test/app/standalone_script_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def command(self) -> list[str]:
command.extend((self.renderer_option, self.renderer_backend))
if self.visualizer is not None:
command.extend((self.spec.visualizer_option, self.visualizer))
if self.physics_backend == "isaacsim_physx" or self.renderer_backend == "isaac_rtx" or self.visualizer == "kit":
command.insert(5, str(Path(__file__).with_name("_standalone_kit.py")))
return command


Expand Down
4 changes: 2 additions & 2 deletions tools/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
"""Per-test startup timeouts for cold external asset downloads."""

PYTEST_WORKERS = {
# Overlapping standalone RTX apps can stall in native renderer destruction on a shared GPU.
"test_standalone_scripts.py": 1,
# Keep standalone launches concurrent within the CI job's existing slot budget.
"test_standalone_scripts.py": 4,
# Contributed-environment smoke tests: environment runs of several seconds to 2 min each. The camera file
# stays whole: its workers would each start the RTX renderer, and one environment dominates it.
"test_contrib_environments_kit.py": 2,
Expand Down
Loading