Skip to content

Commit 7b31c95

Browse files
Change name of the BackgroundService to include name of the class
This makes more readable. Signed-off-by: Elzbieta Kotulska <elzbieta.kotulska@frequenz.com>
1 parent 42d31f1 commit 7b31c95

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/frequenz/sdk/actor/_background_service.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ def __init__(self, *, name: str | None = None) -> None:
7373
"""Initialize this BackgroundService.
7474
7575
Args:
76-
name: The name of this background service. If `None`, `str(id(self))` will
77-
be used. This is used mostly for debugging purposes.
76+
name: The name of this background service. If `None`, id with the
77+
class name will be generated. This is used mostly for debugging purposes.
7878
"""
79-
self._name: str = str(id(self)) if name is None else name
79+
self._name: str = (
80+
f"{self.__class__.__name__}_{id(self)}" if name is None else name
81+
)
8082
self._tasks: set[asyncio.Task[Any]] = set()
8183

8284
@abc.abstractmethod

tests/actor/test_background_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async def nop() -> None:
4747
async def test_construction_defaults() -> None:
4848
"""Test the construction of a background service with default arguments."""
4949
fake_service = FakeService()
50-
assert fake_service.name == str(id(fake_service))
50+
assert fake_service.name.startswith("FakeService_")
5151
assert fake_service.tasks == set()
5252
assert fake_service.is_running is False
5353
assert str(fake_service) == f"FakeService[{fake_service.name}]"

0 commit comments

Comments
 (0)