Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Apr 27, 2023
1 parent 14130c5 commit 0f9c232
Show file tree
Hide file tree
Showing 8 changed files with 534 additions and 747 deletions.
4 changes: 4 additions & 0 deletions crates/re_sdk_comms/src/buffered_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ fn msg_encode(
re_log::error!("Failed to send message to tcp_sender thread. Likely a shutdown race-condition.");
return;
}
// TODO: this is incorrect and dangerous: flush() can return before this
// thread is done with its workload, which means the python process might be
// dead before this thread is dead, which means we call a C callback that has
// been dunload().
if msg_drop_tx.send(msg_msg).is_err() {
re_log::error!("Failed to send message to msg_drop thread. Likely a shutdown race-condition");
return;
Expand Down
4 changes: 2 additions & 2 deletions examples/python/clock/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def rotate(angle: float, len: float) -> Tuple[float, float, float]:

scaled_h = (t_secs % 43200) / 43200.0
point_h = np.array(rotate(math.tau * scaled_h, LENGTH_H))
color_h = (int(255 - (scaled_h * 255)), int(scaled_h * 255), 255, 255)
color_h = (int(255 - (scaled_h * 255)), int(scaled_h * 255), 255, 128)
rr.log_point("world/hours_pt", position=point_h, color=color_h)
rr.log_arrow("world/hours_hand", origin=[0.0, 0.0, 0.0], vector=point_h, color=color_h, width_scale=WIDTH_M)
rr.log_arrow("world/hours_hand", origin=[0.0, 0.0, 0.0], vector=point_h, color=color_h, width_scale=WIDTH_H)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion examples/python/minimal/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
_, unknown = __import__("argparse").ArgumentParser().parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]

rr.spawn()
rr.init("minimal", spawn=True)

positions = np.vstack([xyz.ravel() for xyz in np.mgrid[3 * [slice(-5, 5, 10j)]]]).T
colors = np.vstack([rgb.ravel() for rgb in np.mgrid[3 * [slice(0, 255, 10j)]]]).astype(np.uint8).T
Expand Down
1 change: 1 addition & 0 deletions examples/python/multiprocessing/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def task(title: str) -> None:
# All processes spawned with `multiprocessing` will automatically
# be assigned the same default recording_id.
# We just need to connect each process to the the rerun viewer:
rr.init("multiprocessing")
rr.connect()

rr.log_text_entry(
Expand Down
45 changes: 19 additions & 26 deletions rerun_py/rerun_sdk/rerun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
"ClassDescription",
"LoggingHandler",
"bindings",
"components",
"inline_show",
"ImageFormat",
"log_annotation_context",
"log_arrow",
Expand Down Expand Up @@ -58,7 +56,6 @@
"log_text_entry",
"log_unknown_transform",
"log_view_coordinates",
"notebook",
"LogLevel",
"MeshFormat",
"RectFormat",
Expand Down Expand Up @@ -109,29 +106,13 @@ def get_recording_id() -> str:
return str(bindings.get_recording_id())


def set_recording_id(value: str) -> None:
"""
Set the recording ID that this process is logging to, as a UUIDv4.
The default recording_id is based on `multiprocessing.current_process().authkey`
which means that all processes spawned with `multiprocessing`
will have the same default recording_id.
If you are not using `multiprocessing` and still want several different Python
processes to log to the same Rerun instance (and be part of the same recording),
you will need to manually assign them all the same recording_id.
Any random UUIDv4 will work, or copy the recording id for the parent process.
Parameters
----------
value : str
The recording ID to use for this process.
"""
bindings.set_recording_id(value)


def init(application_id: str, spawn: bool = False, default_enabled: bool = True, strict: bool = False) -> None:
def init(
application_id: str,
recording_id: Optional[str] = None,
spawn: bool = False,
default_enabled: bool = True,
strict: bool = False,
) -> None:
"""
Initialize the Rerun SDK with a user-chosen application id (name).
Expand All @@ -144,6 +125,17 @@ def init(application_id: str, spawn: bool = False, default_enabled: bool = True,
For example, if you have one application doing object detection
and another doing camera calibration, you could have
`rerun.init("object_detector")` and `rerun.init("calibrator")`.
recording_id : Optional[str]
Set the recording ID that this process is logging to, as a UUIDv4.
The default recording_id is based on `multiprocessing.current_process().authkey`
which means that all processes spawned with `multiprocessing`
will have the same default recording_id.
If you are not using `multiprocessing` and still want several different Python
processes to log to the same Rerun instance (and be part of the same recording),
you will need to manually assign them all the same recording_id.
Any random UUIDv4 will work, or copy the recording id for the parent process.
spawn : bool
Spawn a Rerun Viewer and stream logging data to it.
Short for calling `spawn` separately.
Expand Down Expand Up @@ -189,6 +181,7 @@ def init(application_id: str, spawn: bool = False, default_enabled: bool = True,

bindings.init(
application_id=application_id,
recording_id=recording_id,
application_path=application_path,
default_enabled=default_enabled,
)
Expand Down
1 change: 0 additions & 1 deletion rerun_py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ static GLOBAL: AccountingAllocator<mimalloc::MiMalloc> =

mod arrow;
mod python_bridge;
mod python_session;
Loading

0 comments on commit 0f9c232

Please sign in to comment.