File tree Expand file tree Collapse file tree 3 files changed +13
-8
lines changed Expand file tree Collapse file tree 3 files changed +13
-8
lines changed Original file line number Diff line number Diff line change 1717## Bug Fixes
1818
1919- Fixed bug with formulas raising exception when stopped.
20+
21+ - Fix a bug that raised ` CancelledError ` when actor was started with ` frequenz.sdk.actor.run ` and stopped.
Original file line number Diff line number Diff line change @@ -38,18 +38,21 @@ async def run(*actors: Actor) -> None:
3838 done_tasks , pending_tasks = await asyncio .wait (
3939 pending_tasks , return_when = asyncio .FIRST_COMPLETED
4040 )
41-
4241 # This should always be only one task, but we handle many for extra safety
4342 for task in done_tasks :
44- # Cancellation needs to be checked first, otherwise the other methods
45- # could raise a CancelledError
46- if task .cancelled ():
43+ # BackgroundService returns a BaseExceptionGroup containing multiple
44+ # exceptions. The 'task.result()' statement raises these exceptions,
45+ # and 'except*' is used to handle them as a group. If the task raises
46+ # multiple different exceptions, 'except*' will be invoked multiple times,
47+ # once for each exception group.
48+ try :
49+ task .result ()
50+ except* asyncio .CancelledError :
4751 _logger .info ("Actor %s: Cancelled while running." , task .get_name ())
48- elif exception := task . exception ():
49- _logger .error (
52+ except* BaseException : # pylint: disable=broad- exception-caught
53+ _logger .exception (
5054 "Actor %s: Raised an exception while running." ,
5155 task .get_name (),
52- exc_info = exception ,
5356 )
5457 else :
5558 _logger .info ("Actor %s: Finished normally." , task .get_name ())
Original file line number Diff line number Diff 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]: Cancelled while running." ),
394394 (* RUN_INFO , "All 1 actor(s) finished." ),
395395 ]
You can’t perform that action at this time.
0 commit comments