From eb9add5fce88c6eec2d04625b16eb8c94624f970 Mon Sep 17 00:00:00 2001 From: Miguel Xochicale Date: Tue, 20 Feb 2024 22:04:04 +0000 Subject: [PATCH] adds/runs rerun/examples/multithreading #30 --- rerun/README.md | 3 +- rerun/examples/multithreading/README.md | 18 ++++++++ rerun/examples/multithreading/main.py | 42 +++++++++++++++++++ .../examples/multithreading/requirements.txt | 2 + 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 rerun/examples/multithreading/README.md create mode 100644 rerun/examples/multithreading/main.py create mode 100644 rerun/examples/multithreading/requirements.txt diff --git a/rerun/README.md b/rerun/README.md index 7c8b19d..b0b3f1a 100644 --- a/rerun/README.md +++ b/rerun/README.md @@ -1,10 +1,11 @@ # Rerun is an SDK for visualizing multimodal data that changes over time. ## installation +``` mamba update -n base mamba mamba env create -f rrVE.yml mamba activate rrVE - +``` ## References diff --git a/rerun/examples/multithreading/README.md b/rerun/examples/multithreading/README.md new file mode 100644 index 0000000..4cca059 --- /dev/null +++ b/rerun/examples/multithreading/README.md @@ -0,0 +1,18 @@ +# multithreading + +## Download scripts +``` +wget https://raw.githubusercontent.com/rerun-io/rerun/main/examples/python/multithreading/requirements.txt +wget https://raw.githubusercontent.com/rerun-io/rerun/main/examples/python/multithreading/main.py +``` + + +## Run scripts +mamba activate rrVE +pip install -r requirements.txt +python main.py + + +## Reference +https://github.com/rerun-io/rerun/tree/main/examples/python/multithreading + diff --git a/rerun/examples/multithreading/main.py b/rerun/examples/multithreading/main.py new file mode 100644 index 0000000..56a9aba --- /dev/null +++ b/rerun/examples/multithreading/main.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +"""Demonstration of using rerun from multiple threads.""" +from __future__ import annotations + +import argparse +import random +import threading + +import numpy as np +import numpy.typing as npt +import rerun as rr # pip install rerun-sdk + + +def rect_logger(path: str, color: npt.NDArray[np.float32]) -> None: + for _ in range(1000): + rects_xy = np.random.rand(5, 2) * 1024 + rects_wh = np.random.rand(5, 2) * (1024 - rects_xy + 1) + rects = np.hstack((rects_xy, rects_wh)) + rr.log(path, rr.Boxes2D(array=rects, array_format=rr.Box2DFormat.XYWH, colors=color)) + + +def main() -> None: + parser = argparse.ArgumentParser(description="Demonstration of using Rerun from multiple threads.") + rr.script_add_args(parser) + args = parser.parse_args() + + rr.script_setup(args, "rerun_example_multithreading") + + threads = [] + for i in range(5): + t = threading.Thread(target=rect_logger, args=(f"thread/{i}", [random.randrange(255) for _ in range(3)])) + t.start() + threads.append(t) + + for t in threads: + t.join() + + rr.script_teardown(args) + + +if __name__ == "__main__": + main() diff --git a/rerun/examples/multithreading/requirements.txt b/rerun/examples/multithreading/requirements.txt new file mode 100644 index 0000000..fa4ff5d --- /dev/null +++ b/rerun/examples/multithreading/requirements.txt @@ -0,0 +1,2 @@ +numpy +rerun-sdk