Fix race conditions and GH API endpoints#100
Open
theCalcaholic wants to merge 1 commit intojstrieb:masterfrom
Open
Fix race conditions and GH API endpoints#100theCalcaholic wants to merge 1 commit intojstrieb:masterfrom
theCalcaholic wants to merge 1 commit intojstrieb:masterfrom
Conversation
Owner
|
Whoa, this is an awesome find/fix. Thanks! I'd been getting some bug reports about the stats being 0, but had not been able to replicate it myself. As such, I'm really appreciative of this. Haven't had a ton of time for this project, lately. But when I get a chance, I intend to give this a review and get it merged. |
|
Unfortunately, even with this change it's not working for me, it seems the actions are stuck as "Pending", it may be because of this: https://github.com/orgs/community/discussions/119603 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I was investigating, why most of the stats in the overview image were
0lately.Turns out, there was a race condition in the properties awaiting
get_stats().All of these properties would check a field that is supposed to be filled by
get_stats()and if it wasNone, they would await the result ofget_stats(). However, since these fields were set to empty values (e.g.dict()) at the beginning ofget_stats(), some of the async properties ofStatswould return these empty values beforeget_stats()was actually completed, resulting in lots of zeros in the generated images :)So what I changed is this:
Stats._lines_changed,Stats._name...) at the end ofget_stats()rather than the beginningget_stats()to be completed, by introducing anasyncio.Eventand wrappingget_statsin a function that ensures it is only called once and otherwise awaits the event.This is the relevant code:
So
get_statswas renamed to_get_stats. The new functionget_statschecks if the eventStats._get_stats_completedalready exists. If not, it creates it and starts the wrapped function_get_stats, awaits it and then sets the event. If the event already exists, it just waits for it to be set.