Skip to content
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

Don't initialize an SDK session if we are only going to be launching the app #1768

Merged
merged 1 commit into from
Apr 4, 2023
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
7 changes: 6 additions & 1 deletion rerun_py/rerun_sdk/rerun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,18 +306,23 @@ def spawn(port: int = 9876, connect: bool = True) -> None:
print("Rerun is disabled - spawn() call ignored")
return

import os
import subprocess
import sys
from time import sleep

# Let the spawned rerun process know it's just an app
new_env = os.environ.copy()
new_env["RERUN_APP_ONLY"] = "true"

# sys.executable: the absolute path of the executable binary for the Python interpreter
python_executable = sys.executable
if python_executable is None:
python_executable = "python3"

# start_new_session=True ensures the spawned process does NOT die when
# we hit ctrl-c in the terminal running the parent Python process.
subprocess.Popen([python_executable, "-m", "rerun", "--port", str(port)], start_new_session=True)
subprocess.Popen([python_executable, "-m", "rerun", "--port", str(port)], env=new_env, start_new_session=True)

# TODO(emilk): figure out a way to postpone connecting until the rerun viewer is listening.
# For example, wait until it prints "Hosting a SDK server over TCP at …"
Expand Down
21 changes: 15 additions & 6 deletions rerun_py/src/python_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,28 @@ fn rerun_bindings(py: Python<'_>, m: &PyModule) -> PyResult<()> {
// called more than once.
re_log::setup_native_logging();

// We always want main to be available
m.add_function(wrap_pyfunction!(main, m)?)?;

// These two components are necessary for imports to work
// TODO(jleibs): Refactor import logic so all we need is main
m.add_function(wrap_pyfunction!(get_registered_component_names, m)?)?;
m.add_class::<TensorDataMeaning>()?;

// If this is a special RERUN_APP_ONLY context (launched via .spawn), we
// can bypass everything else, which keeps us from preparing an SDK session
// that never gets used.
if matches!(std::env::var("RERUN_APP_ONLY").as_deref(), Ok("true")) {
return Ok(());
}

python_session().set_python_version(python_version(py));

// NOTE: We do this here because we want child processes to share the same recording-id,
// whether the user has called `init` or not.
// See `default_recording_id` for extra information.
python_session().set_recording_id(default_recording_id(py));

m.add_function(wrap_pyfunction!(main, m)?)?;

m.add_function(wrap_pyfunction!(get_registered_component_names, m)?)?;

m.add_function(wrap_pyfunction!(get_recording_id, m)?)?;
m.add_function(wrap_pyfunction!(set_recording_id, m)?)?;

Expand Down Expand Up @@ -150,8 +161,6 @@ fn rerun_bindings(py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(log_cleared, m)?)?;
m.add_function(wrap_pyfunction!(log_arrow_msg, m)?)?;

m.add_class::<TensorDataMeaning>()?;

Ok(())
}

Expand Down