INNER CODE UNIT · Python
restart_camera
MIT-SPARK/VGGT-SLAM · main_realtime.py:50
def restart_camera(camera, stop_event=None, retry_delay: float = 2.0):
"""Stop and re-start the camera, retrying until a device is streaming again.
Used to recover from a mid-session disconnect (e.g. a RealSense USB drop),
where ``capture()`` raises. Honors ``stop_event`` so the user can still
cancel while a camera is unplugged. Returns the working camera object, or
None if aborted via stop_event.
"""
try:
camera.stop()
except Exception:
pass # device may already be gone; ignore teardown errors
attempt = 0
while stop_event is None or not stop_event.is_set():
attempt += 1
try:
camera.start()