openvinotoolkit / openvinotoolkit/physicalai
fix: discover_realsense() re-runs ~2s USB enumeration on every call
@AlbertvanHouten is already working on this.
Since Aug 13, 2026.
- Dominant language
- Python
- Stars
- 28
- Forks
- 22
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 30
Description
Summary
physicalai.capture.discover_all() is slow (>2s per call) because discover_realsense() creates and discards a pyrealsense2 context on every invocation. pyrealsense2 re-runs a full cold USB enumeration (~2s) whenever no rs.context() is alive in the process. Holding a single context alive for the process lifetime makes every discovery instant.
Steps to reproduce
physicalai/capture/cameras/realsense/_discover.py:
def discover_realsense() -> list[DeviceInfo]:
...
ctx = rs_any.context() # local context
for i, dev in enumerate(ctx.query_devices()):
...
return results # ctx is GC'd here → next call pays ~2s again
The context is local, so it's garbage-collected on return. pyrealsense2 tears down its USB enumeration state when the last context dies and re-pays the cold-enumeration cost (~2s) on the next context()/query_devices().
Logs and traceback
Environment
physicalai==0.1.1
macOS, pyrealsense2 installed, no RealSense device connected
Reproducible with zero cameras attached
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.