diff --git a/worker/transcribee_worker/worker.py b/worker/transcribee_worker/worker.py index 1ecefa67..4572b658 100644 --- a/worker/transcribee_worker/worker.py +++ b/worker/transcribee_worker/worker.py @@ -365,14 +365,16 @@ async def _work(): self.keepalive(task_id, self.progress) except Exception as exc: logging.error("Keepliave failed", exc_info=exc) - await asyncio.sleep(seconds) + finally: + await asyncio.sleep(seconds) task = asyncio.create_task(_work()) - yield - - stop_event.set() - await task + try: + yield + finally: + stop_event.set() + await task async def run_task(self, mark_completed=True): task = self.claim_task()