Skip to content
Snippets Groups Projects
Commit 830949f6 authored by Jan David Mol's avatar Jan David Mol
Browse files

Don't break periodic tasks if they raise an exception

parent 55832207
No related branches found
No related tags found
No related merge requests found
...@@ -2,11 +2,14 @@ ...@@ -2,11 +2,14 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import asyncio import asyncio
import logging
from contextlib import suppress from contextlib import suppress
from concurrent.futures import Future, CancelledError from concurrent.futures import Future, CancelledError
from threading import Thread from threading import Thread
from typing import Callable from typing import Callable
logger = logging.getLogger()
class EventLoopThread: class EventLoopThread:
"""A forever running thread that keeps executing the given event_loop.""" """A forever running thread that keeps executing the given event_loop."""
...@@ -88,7 +91,12 @@ class PeriodicTask: ...@@ -88,7 +91,12 @@ class PeriodicTask:
async def _call_periodically(self): async def _call_periodically(self):
while not self.done: while not self.done:
try:
await self.func() await self.func()
except (CancelledError, asyncio.CancelledError):
raise
except Exception as ex:
logger.exception(f"Periodic task {self.func} raised an exception")
# TODO(JDM): Calculate how long to sleep to have the runtime of # TODO(JDM): Calculate how long to sleep to have the runtime of
# func be subtracted. # func be subtracted.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment