Skip to content

Commit

Permalink
Make explicit recordings work without calling rr.init() (#7698)
Browse files Browse the repository at this point in the history
### What
Our recording functions would always check the global recording state
even though they could validly operate just on a manually-created
recording.

With this change, this becomes valid:
```
import rerun as rr

rec = rr.new_recording("rerun_example_cube_flat")

rec.log("points", rr.Points3D([1, 2, 3]))

rec.save("output.rrd")
```
  • Loading branch information
jleibs authored Oct 14, 2024
1 parent 424b9dc commit ce65385
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions rerun_py/rerun_sdk/rerun/sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
# --- Sinks ---


def is_recording_enabled(recording: RecordingStream | None) -> bool:
if recording is not None:
return bindings.is_enabled(recording.inner) # type: ignore[no-any-return]
return bindings.is_enabled() # type: ignore[no-any-return]


def connect(
addr: str | None = None,
*,
Expand Down Expand Up @@ -47,7 +53,7 @@ def connect(
"""

if not bindings.is_enabled():
if not is_recording_enabled(recording):
logging.warning("Rerun is disabled - connect() call ignored")
return

Expand Down Expand Up @@ -102,7 +108,7 @@ def save(
"""

if not bindings.is_enabled():
if not is_recording_enabled(recording):
logging.warning("Rerun is disabled - save() call ignored. You must call rerun.init before saving a recording.")
return

Expand Down Expand Up @@ -149,7 +155,7 @@ def stdout(default_blueprint: BlueprintLike | None = None, recording: RecordingS
"""

if not bindings.is_enabled():
if not is_recording_enabled(recording):
logging.warning("Rerun is disabled - save() call ignored. You must call rerun.init before saving a recording.")
return

Expand Down Expand Up @@ -234,7 +240,7 @@ def serve(
"""

if not bindings.is_enabled():
if not is_recording_enabled(recording):
logging.warning("Rerun is disabled - serve() call ignored")
return

Expand Down Expand Up @@ -346,7 +352,7 @@ def spawn(
"""

if not bindings.is_enabled():
if not is_recording_enabled(recording):
logging.warning("Rerun is disabled - spawn() call ignored.")
return

Expand Down

0 comments on commit ce65385

Please sign in to comment.