Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement async health check methods #945

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions savant/client/runner/healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,26 @@ def wait_module_is_ready(self):
time.sleep(self._check_interval)
self._last_status = self.check()
self._last_check_ts = time.time()

async def async_check(self) -> Optional[str]:
import asyncio

return await asyncio.get_running_loop().run_in_executor(None, self.check)

async def async_wait_module_is_ready(self):
"""Wait until the module is ready. Async version."""
import asyncio

if time.time() - self._last_check_ts >= self._check_interval:
self._last_status = await self.async_check()
self._last_check_ts = time.time()

time_limit = time.time() + self._wait_timeout
while self._last_status != 'running':
if time.time() > time_limit:
raise TimeoutError(
f'Module is not ready after {self._wait_timeout} seconds.'
)
await asyncio.sleep(self._check_interval)
self._last_status = await self.async_check()
self._last_check_ts = time.time()
2 changes: 1 addition & 1 deletion savant/client/runner/sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ async def __anext__(self) -> SinkResult:
"""

if self._health_check is not None:
self._health_check.wait_module_is_ready()
await self._health_check.async_wait_module_is_ready()

wait_until = time.time() + self._idle_timeout
result = None
Expand Down
6 changes: 3 additions & 3 deletions savant/client/runner/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ async def __call__(self, source: Source, send_eos: bool = True) -> SourceResult:

async def send(self, source: Source, send_eos: bool = True) -> SourceResult:
if self._health_check is not None:
self._health_check.wait_module_is_ready()
await self._health_check.async_wait_module_is_ready()

if isinstance(source, tuple) and isinstance(source[0], VideoFrameBatch):
batch, source_id = source
Expand Down Expand Up @@ -366,7 +366,7 @@ async def send_iter(

async def send_eos(self, source_id: str) -> SourceResult:
if self._health_check is not None:
self._health_check.wait_module_is_ready()
await self._health_check.async_wait_module_is_ready()

message, result = self._prepare_eos(source_id)
await self._send_zmq_message(source_id, message)
Expand All @@ -377,7 +377,7 @@ async def send_eos(self, source_id: str) -> SourceResult:

async def send_shutdown(self, zmq_topic: str, auth: str) -> SourceResult:
if self._health_check is not None:
self._health_check.wait_module_is_ready()
await self._health_check.async_wait_module_is_ready()

message, result = self._prepare_shutdown(zmq_topic, auth)
await self._send_zmq_message(zmq_topic, message)
Expand Down