Skip to content

Commit

Permalink
adds/runs rerun/examples/multithreading #30
Browse files Browse the repository at this point in the history
  • Loading branch information
mxochicale committed Feb 20, 2024
1 parent 2780d16 commit eb9add5
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rerun/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 18 additions & 0 deletions rerun/examples/multithreading/README.md
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

42 changes: 42 additions & 0 deletions rerun/examples/multithreading/main.py
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()
2 changes: 2 additions & 0 deletions rerun/examples/multithreading/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
numpy
rerun-sdk

0 comments on commit eb9add5

Please sign in to comment.