From 2846632a31a7dbc487885db3400e05578adaa8db Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= <sybren@stuvel.eu>
Date: Thu, 10 Jan 2019 17:16:11 +0100
Subject: [PATCH] Log error on uncaught exception in Worker.single_iteration()

---
 flamenco_worker/worker.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/flamenco_worker/worker.py b/flamenco_worker/worker.py
index 6482df25..745aa705 100644
--- a/flamenco_worker/worker.py
+++ b/flamenco_worker/worker.py
@@ -296,6 +296,22 @@ class FlamencoWorker:
 
         self.single_iteration_fut = asyncio.ensure_future(self.single_iteration(delay),
                                                           loop=self.loop)
+        self.single_iteration_fut.add_done_callback(self._single_iteration_done)
+
+    def _single_iteration_done(self, future):
+        """Called when self.single_iteration_fut is done."""
+
+        try:
+            ex = future.exception()
+        except asyncio.CancelledError:
+            self._log.debug('single iteration future was cancelled')
+            return
+
+        if ex is None:
+            self._log.debug('single iteration completed without exceptions')
+            return
+
+        self._log.error('Unhandled %s running single iteration: %s', type(ex).__name__, ex)
 
     async def stop_current_task(self, task_id: str):
         """Stops the current task by canceling the AsyncIO task.
-- 
GitLab