Skip to content

Commit 9b84512

Browse files
Log reason for backgroud service stop
Log `msg` argument to simplify debugging. Signed-off-by: Elzbieta Kotulska <elzbieta.kotulska@frequenz.com>
1 parent a2a9066 commit 9b84512

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/frequenz/sdk/actor/_actor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,8 @@ def cancel(self, msg: str | None = None) -> None:
153153
Args:
154154
msg: The message to be passed to the tasks being cancelled.
155155
"""
156+
if msg is not None:
157+
_logger.info("Actor %s cancelled, reason: %s", self, msg)
158+
156159
self._is_cancelled = True
157160
return super().cancel(msg)

src/frequenz/sdk/actor/_background_service.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
import abc
77
import asyncio
88
import collections.abc
9+
import logging
910
from types import TracebackType
1011
from typing import Any, Self
1112

13+
_logger = logging.getLogger(__name__)
14+
1215

1316
class BackgroundService(abc.ABC):
1417
"""A background service that can be started and stopped.
@@ -167,6 +170,10 @@ def cancel(self, msg: str | None = None) -> None:
167170
Args:
168171
msg: The message to be passed to the tasks being cancelled.
169172
"""
173+
_logger.debug(
174+
"Service %s cancelled%s", self, f": {msg}" if msg is not None else ""
175+
)
176+
170177
for task in self._tasks:
171178
task.cancel(msg)
172179

0 commit comments

Comments
 (0)