Skip to content

Commit

Permalink
chg: Cancel a capture running for too long multiple times if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafiot committed Nov 14, 2024
1 parent 32a0ce4 commit f878784
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions bin/capture_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit f878784

Please sign in to comment.