Skip to content

Conversation

@llucax
Copy link
Contributor

@llucax llucax commented Jun 20, 2024

  • Add a unique_id to LatestValueCache
  • Add __str__ and __repr__ to LatestValueCache
  • Cancel LatestValueCache's task if deleted
  • Add @override to PowerDistributingActor

When debugging and having some task in the stack coming from a
`LastValueCache` it is very difficult to identify which one is it.

This commit add a new `unique_id` that's used to create the task name.

Signed-off-by: Leandro Lucarella <[email protected]>
@llucax llucax requested a review from a team as a code owner June 20, 2024 13:32
@github-actions github-actions bot added part:data-pipeline Affects the data pipeline part:actor Affects an actor ot the actors utilities (decorator, etc.) part:core Affects the SDK core components (data structures, etc.) labels Jun 20, 2024
@llucax llucax added the cmd:skip-release-notes It is not necessary to update release notes for this PR label Jun 20, 2024
@llucax llucax added this to the v1.0.0-rc700 milestone Jun 20, 2024
@llucax llucax enabled auto-merge June 20, 2024 13:35
@llucax
Copy link
Contributor Author

llucax commented Jun 20, 2024

Enabled auto-merge.

@llucax llucax added the type:tech-debt Improves the project without visible changes for users label Jun 20, 2024

def __str__(self) -> str:
"""Return a string representation of the cache."""
return str(self._latest_value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the docstring should say the latest value in the cache instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I tend to use just a generic docstring for __str__ and __repr__ but maybe in this case it is worth to be more explicit.


def __del__(self) -> None:
"""Stop the cache when it is deleted."""
self._task.cancel()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best to check if the event loop is still running before calling cancel, else, we might get more warning spam in tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, really? Actually I added this because I was getting warnings in tests about the last value cache tasks being pending when the loop was destroyed. But I debugged the issue and the tasks were properly finished, it seems it might be a bug in pytest-async, I believe we had some similar issues in the past.

Maybe I should remove this and that's it, I think according to Python specs this should not be necessary, and tasks should be cancelled (or discarded) when the even loop is closed, and dangling tasks will also be removed from the loop and finished, it might only happen that this is delayed until the GC runs if the reference was part of a reference loop.

I'd say until we are completely sure this is really necessary we just don't add it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to add more context, this is the issue that made me try this:

llucax added 2 commits June 21, 2024 10:13
The `str` just returns the value, and `repr` gets all the info,
including the new `unique_id`.

We also implement `__str__` for `_Sentinel` to return a more meaningful
string, since it will be shown in the `LatestValueCache` string
representation when no value has been received yet.

Signed-off-by: Leandro Lucarella <[email protected]>
@llucax llucax force-pushed the minor-improvements branch from d8a9326 to e9b2e05 Compare June 21, 2024 08:15
@llucax
Copy link
Contributor Author

llucax commented Jun 21, 2024

Updated to improve the __str__ docstring and removed the commit adding __del__. I also implemented __str__ for _Sentinel so we get a more meaningful string when the cache didn't receive any value yet.

@llucax llucax requested a review from shsms June 21, 2024 08:17
@llucax llucax added this pull request to the merge queue Jun 21, 2024
Merged via the queue into frequenz-floss:v1.x.x with commit a8bb343 Jun 21, 2024
@llucax llucax deleted the minor-improvements branch June 21, 2024 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cmd:skip-release-notes It is not necessary to update release notes for this PR part:actor Affects an actor ot the actors utilities (decorator, etc.) part:core Affects the SDK core components (data structures, etc.) part:data-pipeline Affects the data pipeline type:tech-debt Improves the project without visible changes for users

Projects

Development

Successfully merging this pull request may close these issues.

2 participants