Skip to content

Commit fa0d7f7

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 <[email protected]>
1 parent 855a181 commit fa0d7f7

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
@@ -17,3 +17,5 @@
1717
## Bug Fixes
1818

1919
- Fixed bug with formulas raising exception when stopped.
20+
21+
- 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)