Skip to content

Commit f7d4345

Browse files
committed
Improve links consistency
Now when talking about the `Actor` class, a link to the class is used more consistently. When mentioning the `_run()` method, a link to the "The `_run()` Method" section is provided too. When mentioning frequenz channels, we link using the module instead of using URL. This improves consistency but also makes sure we link to the version the SDK is currently using. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 73acbf3 commit f7d4345

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

src/frequenz/sdk/actor/__init__.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@
3131
provides a straightforward way to implement actors. It shares similarities with
3232
the traditional actor programming model but also has some unique features:
3333
34-
- **Message Passing:** Like traditional actors, our Actor class communicates
35-
through message passing. Even when no particular message passing mechanism is
36-
enforced, the SDK uses [Frequenz Channels][frequenz.channels] for communication.
34+
- **Message Passing:** Like traditional actors, our [`Actor`][frequenz.sdk.actor.Actor]
35+
class communicates through message passing. Even when no particular message passing
36+
mechanism is enforced, the SDK actors use [`frequenz.channels`][] for communication.
3737
3838
- **Automatic Restart:** If an unhandled exception occurs in an actor's logic
39-
(`_run` method), the actor will be automatically restarted. This ensures
39+
([`_run()`][_run] method), the actor will be automatically restarted. This ensures
4040
robustness in the face of errors.
4141
4242
- **Simplified Task Management:** Actors manage asynchronous tasks using
43-
[`asyncio`][]. You can create and manage tasks within the actor, and the `Actor`
44-
class handles task cancellation and cleanup.
43+
[`asyncio`][]. You can create and manage tasks within the actor, and the
44+
[`Actor`][frequenz.sdk.actor.Actor] class handles task cancellation and cleanup.
4545
4646
- **Simplified lifecycle management:** Actors are [async context managers] and also
4747
a [`run()`][frequenz.sdk.actor.run] function is provided.
@@ -148,14 +148,13 @@ async def _run(self) -> None:
148148
## Communication
149149
150150
The [`Actor`][frequenz.sdk.actor.Actor] class doesn't impose any specific way to
151-
communicate between actors. However, [Frequenz
152-
Channels](https://github.com/frequenz-floss/frequenz-channels-python/) are always used
153-
as the communication mechanism between actors in the SDK.
151+
communicate between actors. However, [`frequenz.channels`][] are always used as the
152+
communication mechanism between actors in the SDK.
154153
155154
## Implementing an Actor
156155
157156
To implement an actor, you must inherit from the [`Actor`][frequenz.sdk.actor.Actor]
158-
class and implement the abstract `_run()` method.
157+
class and implement the abstract [`_run()`][_run] method.
159158
160159
### The `_run()` Method
161160
@@ -174,19 +173,19 @@ class and implement the abstract `_run()` method.
174173
[`cancel()`][frequenz.sdk.actor.Actor.cancel] method (which will cancel all the tasks
175174
created by the actor) and will wait for them to finish.
176175
177-
This means that when an actor is stopped, the `_run()` method will receive
176+
This means that when an actor is stopped, the [`_run()`][_run] method will receive
178177
a [`CancelledError`][asyncio.CancelledError] exception. You should have this in mind
179178
when implementing your actor and make sure to handle this exception properly if you need
180179
to do any cleanup.
181180
182181
The actor will handle the [`CancelledError`][asyncio.CancelledError] exception
183-
automatically if it is not handled in the `_run()` method, so if there is no need for
184-
extra cleanup, you don't need to worry about it.
182+
automatically if it is not handled in the [`_run()`][_run] method, so if there is no
183+
need for extra cleanup, you don't need to worry about it.
185184
186-
If an unhandled exception is raised in the `_run()` method, the actor will re-run the
187-
`_run()` method automatically. This ensures robustness in the face of errors, but you
188-
should also have this in mind if you need to do any cleanup to make sure the re-run
189-
doesn't cause any problems.
185+
If an unhandled exception is raised in the [`_run()`][_run] method, the actor will
186+
re-run the [`_run()`][_run] method automatically. This ensures robustness in the face of
187+
errors, but you should also have this in mind if you need to do any cleanup to make sure
188+
the re-run doesn't cause any problems.
190189
191190
???+ tip
192191
@@ -197,8 +196,9 @@ class and implement the abstract `_run()` method.
197196
198197
### Spawning Extra Tasks
199198
200-
Actors run at least one background task, created automatically by the `Actor` class. But
201-
`Actor` inherits from [`BackgroundService`][frequenz.sdk.actor.BackgroundService], which
199+
Actors run at least one background task, created automatically by the
200+
[`Actor`][frequenz.sdk.actor.Actor] class. But [`Actor`][frequenz.sdk.actor.Actor]
201+
inherits from [`BackgroundService`][frequenz.sdk.actor.BackgroundService], which
202202
provides a few methods to create and manage extra tasks.
203203
204204
If your actor needs to spawn extra tasks, you can use
@@ -443,9 +443,9 @@ async def main() -> None: # (6)!
443443
1. We define an `EchoActor` that receives messages from two channels and sends
444444
them to another channel.
445445
446-
2. We implement the `_run()` method that will receive messages from the two channels
447-
using and send them to the output channel. The `run()` method will stop if a `False`
448-
message is received.
446+
2. We implement the [`_run()`][_run] method that will receive messages from the two
447+
channels using and send them to the output channel. The `run()` method will stop if
448+
a `False` message is received.
449449
450450
3. We create the channels that will be used with the actor.
451451
@@ -487,8 +487,8 @@ async def main() -> None: # (6)!
487487
488488
14. Since `selected.value` is `False`, the loop will break.
489489
490-
15. The `_run()` method will finish normally and the actor will be stopped, so the
491-
[`run()`][frequenz.sdk.actor.run] function will return.
490+
15. The [`_run()`][_run] method will finish normally and the actor will be stopped, so
491+
the [`run()`][frequenz.sdk.actor.run] function will return.
492492
493493
16. We close the `echo_channel` to make sure the `echo_receiver` will stop receiving
494494
messages after all the queued messages are consumed (otherwise the step 17 will
@@ -508,6 +508,7 @@ async def main() -> None: # (6)!
508508
```
509509
510510
[async context manager]: https://docs.python.org/3/reference/datamodel.html#async-context-managers
511+
[_run]: #the-_run-method
511512
"""
512513

513514
from ..timeseries._resampling import ResamplerConfig

0 commit comments

Comments
 (0)