-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds/runs rerun/examples/multithreading #30
- Loading branch information
1 parent
2780d16
commit eb9add5
Showing
4 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
numpy | ||
rerun-sdk |