diff --git a/python/mujoco/experimental/studio/sample/ghost.py b/python/mujoco/experimental/studio/sample/ghost.py index 92f384d6..cd95989e 100644 --- a/python/mujoco/experimental/studio/sample/ghost.py +++ b/python/mujoco/experimental/studio/sample/ghost.py @@ -184,9 +184,13 @@ def main(argv: list[str]) -> None: handle.send_to_viewer(messages.ModelEvent(model=model)) step_control = sim.StepControl() - while handle.is_running(): - step_control.advance(model, data) - model, data, step_control = handle.sync(model, data, step_control) + try: + while handle.is_running(): + step_control.advance(model, data) + model, data, step_control = handle.sync(model, data, step_control) + except KeyboardInterrupt: + # Ctrl+C is the documented way to quit; exit cleanly, no traceback. + print('\nShutting down.', flush=True) if __name__ == '__main__': diff --git a/python/mujoco/experimental/studio/sample/implot.py b/python/mujoco/experimental/studio/sample/implot.py index eb9b87e1..a50324cc 100644 --- a/python/mujoco/experimental/studio/sample/implot.py +++ b/python/mujoco/experimental/studio/sample/implot.py @@ -237,9 +237,13 @@ def main(argv: list[str]) -> None: handle.send_to_viewer(messages.ModelEvent(model=model)) step_control = sim.StepControl() - while handle.is_running(): - step_control.advance(model, data) - model, data, step_control = handle.sync(model, data, step_control) + try: + while handle.is_running(): + step_control.advance(model, data) + model, data, step_control = handle.sync(model, data, step_control) + except KeyboardInterrupt: + # Ctrl+C is the documented way to quit; exit cleanly, no traceback. + print('\nShutting down.', flush=True) if __name__ == '__main__': diff --git a/python/mujoco/experimental/studio/viewer.py b/python/mujoco/experimental/studio/viewer.py index 7d773262..e774105d 100644 --- a/python/mujoco/experimental/studio/viewer.py +++ b/python/mujoco/experimental/studio/viewer.py @@ -61,9 +61,13 @@ def main(argv: list[str]) -> None: # Run the simulation. step_control = sim.StepControl() - while handle.is_running(): - step_control.advance(model, data) - model, data, step_control = handle.sync(model, data, step_control) + try: + while handle.is_running(): + step_control.advance(model, data) + model, data, step_control = handle.sync(model, data, step_control) + except KeyboardInterrupt: + # Ctrl+C is the documented way to quit; exit cleanly, no traceback. + print('\nShutting down.', flush=True) _app.run(main)