Skip to content

Make logging of exception which occurred on non main thread less verbose#16074

Merged
seanbudd merged 1 commit into
nvaccess:betafrom
lukaszgo1:I16070
Jan 22, 2024
Merged

Make logging of exception which occurred on non main thread less verbose#16074
seanbudd merged 1 commit into
nvaccess:betafrom
lukaszgo1:I16070

Conversation

@lukaszgo1

Copy link
Copy Markdown
Contributor

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:

  • Documentation:
    • Change log entry
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • API is compatible with existing add-ons.
  • Security precautions taken.

@lukaszgo1 lukaszgo1 requested a review from a team as a code owner January 21, 2024 16:48
@lukaszgo1 lukaszgo1 requested review from seanbudd and removed request for a team January 21, 2024 16:48

@CyrilleB79 CyrilleB79 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this fix @lukaszgo1. Working well!

@seanbudd seanbudd added this to the 2024.1 milestone Jan 22, 2024
@seanbudd seanbudd merged commit 073e3fa into nvaccess:beta Jan 22, 2024
@lukaszgo1 lukaszgo1 deleted the I16070 branch January 22, 2024 10:33
Adriani90 pushed a commit to Adriani90/nvda that referenced this pull request Mar 13, 2024
…ose (nvaccess#16074)

Fixes nvaccess#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 nvaccess#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 p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants