From f8787849445dc9fc8996007d9320a6d460bd30d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Thu, 14 Nov 2024 11:50:58 +0100 Subject: [PATCH] chg: Cancel a capture running for too long multiple times if needed --- bin/capture_manager.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bin/capture_manager.py b/bin/capture_manager.py index 97d9e76..3c31dac 100755 --- a/bin/capture_manager.py +++ b/bin/capture_manager.py @@ -35,11 +35,18 @@ async def clear_dead_captures(self) -> None: elif start_time < oldest_start_time: self.logger.warning(f'{expected_uuid} has been running for too long. Started at {start_time}.') capture = ongoing[expected_uuid] - capture.cancel(f'Capture as been running for more than {max_capture_time}s.') - try: - await capture - except asyncio.CancelledError: - self.logger.warning(f'{expected_uuid} is canceled now.') + max_cancel = 5 + while not capture.done() and max_cancel > 0: + capture.cancel(f'Capture as been running for more than {max_capture_time}s.') + try: + await capture + except asyncio.CancelledError: + self.logger.warning(f'{expected_uuid} is canceled now.') + finally: + max_cancel -= 1 + if not capture.done(): + self.logger.error(f'{expected_uuid} is not done after canceling, trying {max_cancel} more times.') + await asyncio.sleep(1) async def _to_run_forever_async(self) -> None: