From 089d8ab677820f5ca8ad85d2ea05ef3da0a4c9a2 Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Thu, 25 May 2023 11:41:21 +0200 Subject: [PATCH 1/2] Clean up warnings printed when rr.init hasn't been called --- crates/re_sdk/src/global.rs | 27 +++++++++++++++++++ rerun_py/rerun_sdk/rerun/__init__.py | 4 ++- rerun_py/rerun_sdk/rerun/log/log_decorator.py | 4 ++- rerun_py/rerun_sdk/rerun/sinks.py | 2 +- rerun_py/src/python_bridge.rs | 4 +-- 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/crates/re_sdk/src/global.rs b/crates/re_sdk/src/global.rs index 5e15ad4c9ff7..caa00e842653 100644 --- a/crates/re_sdk/src/global.rs +++ b/crates/re_sdk/src/global.rs @@ -65,6 +65,33 @@ impl RecordingStream { rec } + // Internal implementation of `get()` that doesn't print a warning if no recording is found. + // Used from python-bridge. + #[inline] + #[doc(hidden)] + pub fn get_quiet( + which: RecordingType, + overrides: Option, + ) -> Option { + let rec = overrides.or_else(|| { + Self::get_any(RecordingScope::ThreadLocal, which) + .or_else(|| Self::get_any(RecordingScope::Global, which)) + }); + + if rec.is_none() { + // NOTE: This is the one and only place where a warning about missing active recording + // should be printed, don't stutter! + re_log::debug_once!( + "There is no currently active {which} recording available \ + for the current thread ({:?}): have you called `set_global()` and/or \ + `set_thread_local()` first?", + std::thread::current().id(), + ); + } + + rec + } + // --- Global --- /// Returns the currently active recording of the specified type in the global scope, if any. diff --git a/rerun_py/rerun_sdk/rerun/__init__.py b/rerun_py/rerun_sdk/rerun/__init__.py index 1942a00604c8..66a0d801534e 100644 --- a/rerun_py/rerun_sdk/rerun/__init__.py +++ b/rerun_py/rerun_sdk/rerun/__init__.py @@ -419,7 +419,9 @@ def start_web_viewer_server(port: int = 0) -> None: """ if not bindings.is_enabled(): - logging.warning("Rerun is disabled - self_host_assets() call ignored") + logging.warning( + "Rerun is disabled - start_web_viewer_server() call ignored. . You must call rerun.init before starting the web viewer server." + ) return bindings.start_web_viewer_server(port) diff --git a/rerun_py/rerun_sdk/rerun/log/log_decorator.py b/rerun_py/rerun_sdk/rerun/log/log_decorator.py index 815bbd94f6d5..0d1db629c5f0 100644 --- a/rerun_py/rerun_sdk/rerun/log/log_decorator.py +++ b/rerun_py/rerun_sdk/rerun/log/log_decorator.py @@ -32,7 +32,9 @@ def wrapper(*args: Any, **kwargs: Any) -> Any: recording = RecordingStream.to_native(kwargs.get("recording")) if not bindings.is_enabled(recording): # NOTE: use `warnings` which handles runtime deduplication. - warnings.warn(f"Rerun is disabled - {func.__name__}() call ignored") + warnings.warn( + f"Rerun is disabled - {func.__name__}() call ignored. You must call rerun.init before using log APIs." + ) return if rerun.strict_mode(): diff --git a/rerun_py/rerun_sdk/rerun/sinks.py b/rerun_py/rerun_sdk/rerun/sinks.py index d06464732218..ad854e38d1ac 100644 --- a/rerun_py/rerun_sdk/rerun/sinks.py +++ b/rerun_py/rerun_sdk/rerun/sinks.py @@ -50,7 +50,7 @@ def save(path: str, recording: Optional[RecordingStream] = None) -> None: """ if not bindings.is_enabled(): - logging.warning("Rerun is disabled - save() call ignored") + logging.warning("Rerun is disabled - save() call ignored. You must call rerun.init before saving a recording.") return recording = RecordingStream.to_native(recording) diff --git a/rerun_py/src/python_bridge.rs b/rerun_py/src/python_bridge.rs index 2483f0578e1f..9230e396914e 100644 --- a/rerun_py/src/python_bridge.rs +++ b/rerun_py/src/python_bridge.rs @@ -337,7 +337,7 @@ fn get_recording_id(recording: Option<&PyRecordingStream>) -> Option { /// specified recording otherwise, if any. #[pyfunction] fn get_data_recording(recording: Option<&PyRecordingStream>) -> Option { - RecordingStream::get( + RecordingStream::get_quiet( rerun::RecordingType::Data, recording.map(|rec| rec.0.clone()), ) @@ -408,7 +408,7 @@ fn set_thread_local_data_recording( /// specified recording otherwise, if any. #[pyfunction] fn get_blueprint_recording(overrides: Option<&PyRecordingStream>) -> Option { - RecordingStream::get( + RecordingStream::get_quiet( rerun::RecordingType::Blueprint, overrides.map(|rec| rec.0.clone()), ) From 9379f7a86a77786f52242a3249d78765e0fa1f33 Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Thu, 25 May 2023 12:03:43 +0200 Subject: [PATCH 2/2] Split long log line --- rerun_py/rerun_sdk/rerun/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rerun_py/rerun_sdk/rerun/__init__.py b/rerun_py/rerun_sdk/rerun/__init__.py index 66a0d801534e..116e5ab25b5c 100644 --- a/rerun_py/rerun_sdk/rerun/__init__.py +++ b/rerun_py/rerun_sdk/rerun/__init__.py @@ -420,7 +420,8 @@ def start_web_viewer_server(port: int = 0) -> None: if not bindings.is_enabled(): logging.warning( - "Rerun is disabled - start_web_viewer_server() call ignored. . You must call rerun.init before starting the web viewer server." + "Rerun is disabled - start_web_viewer_server() call ignored. You must call rerun.init before starting the" + + " web viewer server." ) return