-
Couldn't load subscription status.
- Fork 20
Make some minor improvements for LastValueCache #974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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]>
|
Enabled auto-merge. |
|
|
||
| def __str__(self) -> str: | ||
| """Return a string representation of the cache.""" | ||
| return str(self._latest_value) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
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]>
Signed-off-by: Leandro Lucarella <[email protected]>
d8a9326 to
e9b2e05
Compare
|
Updated to improve the |
unique_idtoLatestValueCache__str__and__repr__toLatestValueCacheLatestValueCache's task if deleted@overridetoPowerDistributingActor