system/ui: throttle camera connection attempts (#35343)

throttle connection attempts
pull/35347/head
Dean Lee 2 weeks ago committed by GitHub
parent eabee8c73f
commit 22715464b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 11
      system/ui/widgets/cameraview.py

@ -5,6 +5,8 @@ from openpilot.system.ui.lib.application import gui_app
from openpilot.system.ui.lib.egl import init_egl, create_egl_image, destroy_egl_image, bind_egl_image_to_texture, EGLImage
CONNECTION_RETRY_INTERVAL = 0.2 # seconds between connection attempts
VERTEX_SHADER = """
#version 300 es
in vec3 vertexPosition;
@ -53,6 +55,7 @@ else:
class CameraView:
def __init__(self, name: str, stream_type: VisionStreamType):
self.client = VisionIpcClient(name, stream_type, False)
self.last_connection_attempt: float = 0.0
self.shader = rl.load_shader_from_memory(VERTEX_SHADER, FRAME_FRAGMENT_SHADER)
self.frame: VisionBuf | None = None
@ -159,6 +162,14 @@ class CameraView:
def _ensure_connection(self) -> bool:
if not self.client.is_connected():
self.frame = None
# Throttle connection attempts
current_time = rl.get_time()
if current_time - self.last_connection_attempt < CONNECTION_RETRY_INTERVAL:
return False
self.last_connection_attempt = current_time
if not self.client.connect(False) or not self.client.num_buffers:
return False

Loading…
Cancel
Save