Repository navigation
gh-156082: Do not run tests using the same machine-wide resource at once #156902
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
serhiy-storchaka
wants to merge
3
commits into
python:main
Choose a base branch
from
serhiy-storchaka:test-support-exclusive-resource
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
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
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Address the review
Name the lock files, so that it is clear what left them in the temporary directory, and say why they are left. Close the file descriptor whatever goes wrong. Call the resource of bigmem tests 'bigmem'. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
- Loading branch information
commit 3d90c4345c6fd045db1cdffdc9d80384b2b2ec74
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -339,7 +339,8 @@ def get_resource_value(resource): | |
|
|
||
| # Resources which are machine-wide: two tests using one of them at the same | ||
| # time interfere with each other. | ||
| EXCLUSIVE_RESOURCES = frozenset({'audio', 'console', 'curses', 'gui'}) | ||
| EXCLUSIVE_RESOURCES = frozenset({'audio', 'bigmem', 'console', 'curses', | ||
| 'gui'}) | ||
|
|
||
| # The environment variable naming the directory in which the test runner keeps | ||
| # the lock files. It is set only when tests are run in parallel. | ||
|
|
@@ -359,7 +360,7 @@ def _lock_file(fd): | |
| try: | ||
| msvcrt.locking(fd, msvcrt.LK_NBLCK, 1) | ||
| except OSError: | ||
| # LK_LOCK gives up after ten seconds, so retry ourselves. | ||
| # It returns at once if the file is locked, so wait ourselves. | ||
| time.sleep(0.1) | ||
| else: | ||
| return | ||
|
|
@@ -377,16 +378,22 @@ def _open_exclusive_lock(resource): | |
| if not directory: | ||
| # The tests are not run in parallel, so there is nothing to exclude. | ||
| return None | ||
| # The file is left behind: another process may be waiting on a lock on it, | ||
| # and it is empty anyway. | ||
| path = os.path.join(directory, f'python-test-exclusive-{resource}.lock') | ||
| try: | ||
| fd = os.open(os.path.join(directory, f'exclusive-{resource}.lock'), | ||
| os.O_WRONLY | os.O_CREAT, 0o600) | ||
| fd = os.open(path, os.O_WRONLY | os.O_CREAT, 0o600) | ||
| except OSError: | ||
| return None | ||
| try: | ||
| _lock_file(fd) | ||
| except OSError: | ||
| except (ImportError, OSError): | ||
| # Locking is not available here, so the tests are not serialized. | ||
| os.close(fd) | ||
| return None | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a catch-all "except: os.close(fd); raise" to make sure that the file descriptor is closed if something goes wrong. For example, if "import fcntl" and "import msvcrt" both raise an exception. |
||
| except BaseException: | ||
| os.close(fd) | ||
| raise | ||
| return fd | ||
|
|
||
|
|
||
|
|
@@ -1454,7 +1461,7 @@ def wrapper(self): | |
| cls = type(self) | ||
| qualname = f'{cls.__qualname__}.{f.__name__}' | ||
| # A real run allocates most of the memory of the machine. | ||
| with _exclusive_resource('memory'): | ||
| with _exclusive_resource('bigmem'): | ||
| proc = isolation._start_test(cls.__module__, qualname) | ||
| watchdog = _memory_watchdog(proc.pid) if verbose else None | ||
| payload, output, returncode = proc.wait(tick=watchdog) | ||
|
|
||
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.
The logic and intent of this is not clear to me.