File tree Expand file tree Collapse file tree 3 files changed +15
-2
lines changed
Expand file tree Collapse file tree 3 files changed +15
-2
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 66
77import asyncio
88import logging
9+ from typing import Any
910
1011from ._actor import Actor
1112
@@ -43,7 +44,7 @@ async def run(*actors: Actor) -> None:
4344 for task in done_tasks :
4445 # Cancellation needs to be checked first, otherwise the other methods
4546 # could raise a CancelledError
46- if task . cancelled ( ):
47+ if _was_cancelled ( task ):
4748 _logger .info ("Actor %s: Cancelled while running." , task .get_name ())
4849 elif exception := task .exception ():
4950 _logger .error (
@@ -55,3 +56,13 @@ async def run(*actors: Actor) -> None:
5556 _logger .info ("Actor %s: Finished normally." , task .get_name ())
5657
5758 _logger .info ("All %s actor(s) finished." , len (actors ))
59+
60+
61+ def _was_cancelled (task : asyncio .Task [Any ]) -> bool :
62+ if task .cancelled ():
63+ return True
64+
65+ exc = task .exception ()
66+ return isinstance (exc , BaseExceptionGroup ) and all (
67+ isinstance (err , asyncio .CancelledError ) for err in exc .exceptions
68+ )
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