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
Refactor loader.py #8560
Open
Julian-O
wants to merge
9
commits into
kivy:master
Choose a base branch
from
Julian-O:asyncexception
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Refactor loader.py #8560
Conversation
This file contains 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
Raise ValueError ("Raised when an operation or function receives an argument that has the right type but an inappropriate value, and the situation is not described by a more precise exception such as IndexError."), so they can be specifically caught by clients.
Catch the expected exceptions only. Do not suppress Out Of Memory errors, abort commands and other unexpected exceptions.
Simplify code by using contextmanager.
Old code would catch all exceptions, not just expected exceptions. In fact, old code had no expected exceptions - code would still run if filename was missing! Added explicit check to catch missing filename. Logged, because this is probable not a good thing.
Minimise scope of try block. Consistently set file handles to None after closing. Simplify truthiness check for _out_filename
The cache belongs to the module, not the instance. Also a couple of comment edits.
Save CPU (and be more responsive) by not checking for stoppages and grabbing and releasing locks at 4Hz.
The clean-up formerly in __del__ () is now in stop(), where it belongs. [There is no guarantee that __del__() is called in a timely manner, or even at all, so there should be no non-trivial logic in that method. Common trap for C++ programmers.]
Julian-O
force-pushed
the
asyncexception
branch
from
January 13, 2024 14:12
cded6f6
to
bdc8c5b
Compare
Please hold off on this review/merge. I am considering a larger refactor that will render this moot. |
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.
This refactor adds no new functionality, but improves the code to improve logging, exception handling and shut-down behaviour.
Each commit tackles a different issue:
Unexpected exceptions in worker thread tasks were printed to the screen rather than properly logged. This was a contributing factor to "bad transparency mask" error animated gifs #8555 being hard to debug. (This only addresses Point 3 in my comment there, and does not close the issue.)
Avoid raising direct instances of the Exception class - used ValueError instead.
Avoid catch blocks which don't specify exceptions. Caught IndexError instead.
threading.Condition
supports context managers, which simplifies code (ensures acquires and releases are perfectly matched)Code purported to catch an exception if a filename was empty, but didn't. Added an explicit check and logged that fact if it occurred.
Ensured files were closed, and file handlers were not reused afterwards.
Declared an existing static method as static.
Old code checked 4 times a second if it had been stopped. Replaced with a signal to remove the busy wait and wasted CPU.
Old code cleaned up a clock action only if the garbage collector happened to run. Now, it is cleaned up on
stop()
.There are no API changes here. In theory, the existing unit-tests should be sufficient. However, I currently can't see the coverage (most of the unit tests don't run on my Windows dev machine). Waiting for merge to see what is needed for the coveralls report.
Maintainer merge checklist
Component: xxx
label.api-deprecation
orapi-break
label.release-highlight
label to be highlighted in release notes.versionadded
,versionchanged
as needed.