Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve error handling, through additional exception handler in done_callback #144

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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 @@
)
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
Loading