-
Notifications
You must be signed in to change notification settings - Fork 17
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
Improve the power managing actor initialization #966
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]>
The `str` just returns the value, and `repr` gets all the info, including the new `unique_id`. Signed-off-by: Leandro Lucarella <[email protected]>
This shouldn't be strictly necessary as the even loop only store weak references to tasks, and when a task is gone it should be removed from the event loop anyway, but this makes the process more explicit and might help cleaning up more properly if the task was still running when deleted, as the `CancelledError` might be still raised inside the task, giving it the opportunity to clean up. Signed-off-by: Leandro Lucarella <[email protected]>
This methods allows to wait until the cache is filled, to ensure working with a valid value at some particular point in time. Signed-off-by: Leandro Lucarella <[email protected]>
This method will wait that the manager actually received some data to ensure it can make informed decisions, and it is not just working on a partially initialized system. Signed-off-by: Leandro Lucarella <[email protected]>
Signed-off-by: Leandro Lucarella <[email protected]>
Instead of blindly waiting for some time in the hopes that the underlying manager got some data, which can be a longer-than-needed wait when the data is available pretty quickly, we ask the manager to wait until the data is ready by using the new `wait_for_data()` method. Signed-off-by: Leandro Lucarella <[email protected]>
@jh2007github FYI as it is (slightly) related to frequenz-floss/frequenz-core-python#7. |
Skipping release notes as the resulting effect should be barely noticeable for end users, but I can mention the improvement in the release notes if you prefer. |
The waiting for data at power distributor startup can be dropped instead: #971, so I guess some of the commits from this PR can go away. |
We leave the wait for data for |
This PR was done while chasing an issue with tests complaining that some tasks were pending while the loop was destroyed.
I guess the issue is in the
pytest_asyncio
plugin, because those tasks seem to be properly cancelled according to my debugging, and we had similar issues withpytest-asyncio
before. The weird thing is that the errors show up in a different test from the one that actually creates the tasks, which makes me think that the plugin is not properly cleaning up after itself.In any case, while debugging this, I found a few things that could be improved in the code in terms of synchoronization during initialization and cleanup.
This PR:
unique_id
toLatestValueCache
to improve the debugging experience (using the new nameunique_id
instead ofname
, as suggested in RenameBackgroundService
'sname
argument tounique_id
frequenz-core-python#7).__str__
and__repr__
toLatestValueCache
to use thisunique_id
LatestValueCache
's task if deleted (just in case)wait_for_value()
method toLatestValueCache
so we can wait for the cache to be filled with datawait_for_data()
method toComponentManager
to wait for all caches to be filled with data@override
toPowerDistributingActor
(because why not?)PowerDistributingActor
by using the newwait_for_data()
method instead of blidly wait for the whole wait time