-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-133532: Run GC fast cycles test in subprocess. #133533
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
nascheme
merged 5 commits into
python:main
from
nascheme:gh-133532-gc-test-in-subprocess
May 8, 2025
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3bb8b94
gh-133532: Run GC fast cycles test in subprocess.
nascheme d37ed70
Remove unused 'count' variable.
nascheme 3a4f984
Merge branch 'main' into gh-133532-gc-test-in-subprocess
nascheme d3188ca
Merge branch 'main' into gh-133532-gc-test-in-subprocess
AA-Turner f389828
Merge branch 'main' into gh-133532-gc-test-in-subprocess
nascheme 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Run by test_gc. | ||
| from test import support | ||
| import _testinternalcapi | ||
| import gc | ||
| import unittest | ||
|
|
||
| class IncrementalGCTests(unittest.TestCase): | ||
|
|
||
| # Use small increments to emulate longer running process in a shorter time | ||
| @support.gc_threshold(200, 10) | ||
| def test_incremental_gc_handles_fast_cycle_creation(self): | ||
|
|
||
| class LinkedList: | ||
|
|
||
| #Use slots to reduce number of implicit objects | ||
| __slots__ = "next", "prev", "surprise" | ||
|
|
||
| def __init__(self, next=None, prev=None): | ||
| self.next = next | ||
| if next is not None: | ||
| next.prev = self | ||
| self.prev = prev | ||
| if prev is not None: | ||
| prev.next = self | ||
|
|
||
| def make_ll(depth): | ||
| head = LinkedList() | ||
| for i in range(depth): | ||
| head = LinkedList(head, head.prev) | ||
| return head | ||
|
|
||
| head = make_ll(1000) | ||
| count = 1000 | ||
|
|
||
| assert(gc.isenabled()) | ||
| olds = [] | ||
| initial_heap_size = _testinternalcapi.get_tracked_heap_size() | ||
| for i in range(20_000): | ||
| newhead = make_ll(20) | ||
| count += 20 | ||
| newhead.surprise = head | ||
| olds.append(newhead) | ||
| if len(olds) == 20: | ||
| new_objects = _testinternalcapi.get_tracked_heap_size() - initial_heap_size | ||
| self.assertLess(new_objects, 27_000, f"Heap growing. Reached limit after {i} iterations") | ||
| del olds[:] | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.