-
-
Notifications
You must be signed in to change notification settings - Fork 112
Improve error handling for Windows and MSS context #519
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
Merged
BoboTiG
merged 5 commits into
BoboTiG:main
from
halldorfannar:task/improve-error-handling
Apr 29, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4aa72d4
Improve error handling in Windows path
halldorfannar 2858346
Fix issues found by check script
halldorfannar c16e5b8
Add notes about changes
halldorfannar 264fb6d
Fix exception handling in thread tests for Windows
halldorfannar 4b261f1
Add new thread_helpers.py to sdist test
halldorfannar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| """Helpers for tests that need to run work on background threads.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import threading | ||
| import time | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| if TYPE_CHECKING: | ||
| from collections.abc import Callable | ||
|
|
||
|
|
||
| def run_threads(*targets: Callable[[], None], start_delay: float = 0.0) -> None: | ||
| errors: list[Exception] = [] | ||
|
|
||
| def record(target: Callable[[], None]) -> None: | ||
| try: | ||
| target() | ||
| except Exception as exc: # noqa: BLE001 - transport worker failures to the main test thread. | ||
| errors.append(exc) | ||
|
|
||
| threads = [threading.Thread(target=record, args=(target,)) for target in targets] | ||
| for index, thread in enumerate(threads): | ||
| thread.start() | ||
| if start_delay and index < len(threads) - 1: | ||
| time.sleep(start_delay) | ||
| for thread in threads: | ||
| thread.join() | ||
|
|
||
| if errors: | ||
| raise errors[0] |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't these normally be chained? Is there a reason not to use chained exceptions here? I'm a little hesitant to just swallow exceptions entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. When a
withbody is already failing, and__exit__also fails during cleanup, chaining creates the wrong relationship and headline. Python/pytest reports the exception raised from__exit__as the active failure, so the real body failure becomes secondary context. That was the ReleaseDC masking the actual BitBlt/thread failure in the PR that triggered this work.Python 3.11 has a new feature that is designed for this case, https://docs.python.org/3/library/exceptions.html#lib-exception-groups - but we cannot use that since we support 3.10.