Skip to content

Commit

Permalink
improve error handling, through additional exception handler in don_c…
Browse files Browse the repository at this point in the history
…allback#

These exception fail silently otherwise
  • Loading branch information
maurerle committed Dec 9, 2024
1 parent f89fd83 commit be6d444
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mango/util/distributed_clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ async def get_next_event(self):
if self.schedules:
next_event = min(self.schedules)
else:
logger.warning("%s: no new events, time stands still", self.aid)
logger.info("%s: no new events, time stands still", self.aid)
next_event = self.scheduler.clock.time

if next_event < self.scheduler.clock.time:
logger.warning("%s: got old event, time stands still", self.aid)
logger.info("%s: got old event, time stands still", self.aid)

Check warning on line 128 in mango/util/distributed_clock.py

View check run for this annotation

Codecov / codecov/patch

mango/util/distributed_clock.py#L128

Added line #L128 was not covered by tests
next_event = self.scheduler.clock.time
logger.debug("next event at %s", next_event)
return next_event
Expand Down
17 changes: 17 additions & 0 deletions mango/util/scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import asyncio
import concurrent.futures
import datetime
import logging
from abc import abstractmethod
from asyncio import Future
from dataclasses import dataclass
Expand All @@ -16,6 +17,20 @@

from mango.util.clock import AsyncioClock, Clock, ExternalClock

logger = logging.getLogger(__name__)


def _raise_exceptions(fut: asyncio.Future):
"""
Inline function used as a callback to raise exceptions
:param fut: The Future object of the task
"""
if fut.exception() is not None:
try:
raise fut.exception()
except Exception:
logger.exception("got exception in scheduled event")

Check warning on line 32 in mango/util/scheduling.py

View check run for this annotation

Codecov / codecov/patch

mango/util/scheduling.py#L29-L32

Added lines #L29 - L32 were not covered by tests


@dataclass
class ScheduledProcessControl:
Expand Down Expand Up @@ -507,6 +522,7 @@ def schedule_task(self, task: ScheduledTask, src=None) -> asyncio.Task:
coro = task.run()
l_task = asyncio.create_task(coro)
l_task.add_done_callback(task.on_stop)
l_task.add_done_callback(_raise_exceptions)
l_task.add_done_callback(self._remove_task)
self._scheduled_tasks.append((task, l_task, coro, src))
return l_task
Expand Down Expand Up @@ -703,6 +719,7 @@ def schedule_process_task(self, task: ScheduledProcessTask, src=None):
)
l_task.add_done_callback(self._remove_process_task)
l_task.add_done_callback(task.on_stop)
l_task.add_done_callback(_raise_exceptions)
self._scheduled_process_tasks.append(
(task, l_task, scheduled_process_control, src)
)
Expand Down

0 comments on commit be6d444

Please sign in to comment.