Add custom hooks for unraisable exceptions, to log exceptions raised in ctypes callback functions in a more readable way#16169
Merged
Conversation
…in ctypes callback functions in a more readable way
Contributor
Author
|
cc @CyrilleB79 |
Contributor
|
Thanks for this fix @lukaszgo1! |
seanbudd
reviewed
Feb 13, 2024
seanbudd
approved these changes
Feb 13, 2024
Adriani90
pushed a commit
to Adriani90/nvda
that referenced
this pull request
Mar 13, 2024
…in ctypes callback functions in a more readable way (nvaccess#16169) Fixes nvaccess#16115 Summary of the issue: When an exception is raised in ctypes callback function Python cannot handle it in any reasonable way, so the traceback gets printed to stderr. Somewhere after Python 3.7 a change was made, so that it is printed line by line. As a result we get as many log entries as there were lines in the traceback making logging extremely noisy. Description of user facing changes Exceptions from ctypes callback functions once again results in a single log entry. Description of development approach Since Python 3.8 it is possible to customize how these so called unraisable exceptions are handle. This PR adds a handler which logs them in a readable format, mostly based on how the native Python's hook does this.
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.
Opened against beta since this PR fixes regression caused by the upgrade to Python 3.11, and the change is very low risk.
Link to issue number:
Fixes #16115
Summary of the issue:
When an exception is raised in
ctypescallback function Python cannot handle it in any reasonable way, so the traceback gets printed to stderr. Somewhere after Python 3.7 a change was made, so that it is printed line by line. As a result we get as many log entries as there were lines in the traceback making logging extremely noisy.Description of user facing changes
Exceptions from
ctypescallback functions once again results in a single log entry.Description of development approach
Since Python 3.8 it is possible to customize how these so called unraisable exceptions are handle. This PR adds a handler which logs them in a readable format, mostly based on how the native Python's hook does this.
Testing strategy:
Raised an exception in
winInputHook.keyboardHook, ensured it results in a single, readable log entry.Known issues with pull request:
None known
Code Review Checklist: