Make logging of exception which occurred on non main thread less verbose #16074
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.
Link to issue number:
Fixes #16070
Summary of the issue:
To log unhandled exceptions NVDA relies on a custom except hook installed when initializing logging. Until Python 3.8 custom except hooks were not called for exception which occurred outside of the main thread - they were simply written to stderr (see python/cpython#42148). This worked well for NVDA, since it replaces stderr with a custom object which logs everything written to stderr, so the exceptions ended up in our log, just in a different way. In Python 3.8 it become possible to install a custom hook which gets called for exceptions which are raised in non main threads, but as part of this change the way in which they are handled by default has changed - the traceback is written to stderr line by line, rather than as a single call to
print
as it used to be. For NVDA it means that each line of the traceback results in a separate log entry making logging extremely noisy.Description of user facing changes
Exception from threads different than the main one are logged in the same way as they were in NVDA 2023.3.
Description of development approach
A custom except hook for exception raised in threads was introduced. It logs them as an exception with additional information explaining in which thread they were raised.
Testing strategy:
Performed STR from #16070 - ensured that logging looks similarly to the one from 2023.3 and that single exception results in a single log entry.
Known issues with pull request:
None known
Code Review Checklist: