Skip to content

Add detach_process option to spawn #9400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

imstevenpmwork
Copy link
Contributor

@imstevenpmwork imstevenpmwork commented Mar 27, 2025

Related Discussion

For more context, see this thread:
https://discord.com/channels/1062300748202921994/1354497232103145642
Related to: 1942b43

What’s New

This update introduces a detach_process option for the spawn() method in the Viewer (available in Rust, Python, and C++).

Why It Matters

This gives client code control over whether the Viewer runs independently of the parent process or remains tied to it. Keeping it attached ensures the Viewer closes when the parent process terminates with SIGINT. Detaching (default behavior) allows it to persist if needed.

While this achieves the desired functionality, a future improvement could be adding a proper close() method to gracefully shut down the Viewer context.

Note on Web Support

This change wasn’t applied to the web API since I'm not sure how process management behaves there.

How it was tested?

(Python only) Small edit to the minimal.py to evaluate the behavior

#!/usr/bin/env python3
"""Demonstrates the most barebone usage of the Rerun SDK."""

from __future__ import annotations

import sys

import numpy as np
import rerun as rr  # pip install rerun-sdk
import time


def main() -> None:
    # sanity-check since all other example scripts take arguments:
    assert len(sys.argv) == 1, f"{sys.argv[0]} does not take any arguments"

    rr.init("rerun_example_minimal")
    rr.spawn(detach_process=False)

    positions = np.vstack([xyz.ravel() for xyz in np.mgrid[3 * [slice(-10, 10, 10j)]]]).T
    colors = np.vstack([rgb.ravel() for rgb in np.mgrid[3 * [slice(0, 255, 10j)]]]).astype(np.uint8).T

    rr.log("my_points", rr.Points3D(positions, colors=colors, radii=0.5))
    time.sleep(10)  # CRTL+C here: Viewer process will exit


if __name__ == "__main__":
    main()

As expected, when detach_process=False if we send a SIGINT to the application, the Viewer exits and the PID assigned to it is retired.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Thanks for opening this pull request.

Because this is your first time contributing to this repository, make sure you've read our Contributor Guide and Code of Conduct.

Copy link
Member

@emilk emilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great so far!

@imstevenpmwork imstevenpmwork marked this pull request as ready for review March 28, 2025 16:26
@imstevenpmwork imstevenpmwork changed the title feat(viewer): add detach_process option feat(viewer): add detach_process option Mar 28, 2025
@emilk emilk added 🐍 Python API Python logging API 🦀 Rust API Rust logging API 🌊 C++ API C/C++ API specific include in changelog labels Mar 31, 2025
@emilk emilk added this to the 0.23.0 milestone Mar 31, 2025
@emilk emilk changed the title feat(viewer): add detach_process option Add detach_process option to spawn Mar 31, 2025
@emilk
Copy link
Member

emilk commented Mar 31, 2025

The CI failures seems unrelated. The C++ tests passes locally.

@emilk emilk merged commit 075e5c3 into rerun-io:main Mar 31, 2025
31 of 33 checks passed
@emilk emilk mentioned this pull request Apr 11, 2025
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌊 C++ API C/C++ API specific include in changelog 🐍 Python API Python logging API 🦀 Rust API Rust logging API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants