Skip to content

Commit 4579627

Browse files
Stop raising exception on BackgroundService cancell
Cancelling BackgroundService should not raise exception. We cancell it when we stop actor, after calling `actor.wait()`. Signed-off-by: Elzbieta Kotulska <elzbieta.kotulska@frequenz.com>
1 parent 38c91e5 commit 4579627

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
- Fixed a bug that was preventing power proposals to go through if there once existed some proposals with overlapping component IDs, even if the old proposals have expired.
1010

1111
- Fixed a bug that was causing formulas to fallback to CHPs, when the CHP meters didn't have data. CHPs are not supported in the data sourcing actor and in the client, so we can't fallback to CHPs.
12+
13+
- Fix a bug that caused BackgroundService to raise exception when actor was stopped.

src/frequenz/sdk/actor/_background_service.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
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

@@ -251,6 +252,8 @@ async def wait(self) -> None:
251252
# This will raise a CancelledError if the task was cancelled or any
252253
# other exception if the task raised one.
253254
_ = task.result()
255+
except asyncio.CancelledError:
256+
logging.debug("Task %s has been cancelled", self.name)
254257
except BaseException as error: # pylint: disable=broad-except
255258
exceptions.append(error)
256259
if exceptions:

tests/actor/test_actor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,6 @@ async def cancel_actor() -> None:
390390
(*RUN_INFO, "Actor EchoActor[EchoActor]: Starting..."),
391391
(*ACTOR_INFO, "Actor EchoActor[EchoActor]: Started."),
392392
(*ACTOR_INFO, "Actor EchoActor[EchoActor]: Cancelled."),
393-
(*RUN_ERROR, "Actor EchoActor[EchoActor]: Raised an exception while running."),
393+
(*RUN_INFO, "Actor EchoActor[EchoActor]: Finished normally."),
394394
(*RUN_INFO, "All 1 actor(s) finished."),
395395
]

0 commit comments

Comments
 (0)