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

Clean up warnings printed when rr.init hasn't been called #2209

Merged
merged 2 commits into from
May 25, 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
27 changes: 27 additions & 0 deletions crates/re_sdk/src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RecordingStream>,
) -> Option<RecordingStream> {
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.
Expand Down
5 changes: 4 additions & 1 deletion rerun_py/rerun_sdk/rerun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,10 @@ 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)
4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/log/log_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion rerun_py/rerun_sdk/rerun/sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions rerun_py/src/python_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ fn get_recording_id(recording: Option<&PyRecordingStream>) -> Option<String> {
/// specified recording otherwise, if any.
#[pyfunction]
fn get_data_recording(recording: Option<&PyRecordingStream>) -> Option<PyRecordingStream> {
RecordingStream::get(
RecordingStream::get_quiet(
rerun::RecordingType::Data,
recording.map(|rec| rec.0.clone()),
)
Expand Down Expand Up @@ -408,7 +408,7 @@ fn set_thread_local_data_recording(
/// specified recording otherwise, if any.
#[pyfunction]
fn get_blueprint_recording(overrides: Option<&PyRecordingStream>) -> Option<PyRecordingStream> {
RecordingStream::get(
RecordingStream::get_quiet(
rerun::RecordingType::Blueprint,
overrides.map(|rec| rec.0.clone()),
)
Expand Down