-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-34042: Fix dict.copy() to maintain correct total refcount #8119
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
Conversation
Lib/test/test_dict.py
Outdated
|
||
for i in range(10): | ||
dct.copy() | ||
first_ref_count = gettotalrefcount() |
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.
Should it be in the loop?
Lib/test/test_dict.py
Outdated
'debug build required') | ||
def test_copy_global_refcount(self): | ||
# See issue #34042 for more details. | ||
first_ref_count = second_ref_count = None |
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.
What is the reason of this initialization?
Lib/test/test_dict.py
Outdated
|
||
for i in range(10): | ||
dct.copy() | ||
first_ref_count = gettotalrefcount() |
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.
Why getting the total for each iteration of the loop?
@vstinner @serhiy-storchaka The test is structured in a weird way because that's the only way how I can get it stable on my machine. And yet, here's a CI failure:
Any suggestions on how I can write a reliable test for |
Since this is debug feature, I'm OK for this instead of maintain cryptic, fragile test. |
What about using dct = {'a': 1}
support.gc_collect()
first_ref_count = sys.gettotalrefcount()
for i in range(1000):
dct.copy()
support.gc_collect()
second_ref_count = sys.gettotalrefcount()
self.assertAlmostEqual(first_ref_count, second_ref_count, delta=10) |
Please don't use fragile tests. I already have enough issues with existing fragile tests. +1 to commit without tests. |
Honestly, Python internals are too complex to get a reliable total reference count. I'm ok to remove the test. regrtest usually runs a test 3 times to "warmup caches" before checking for reference leaks, and also use many low-level "cleanup" functions to help to get reliable reference counts. |
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.
LGTM.
Thanks @1st1 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7. |
GH-8143 is a backport of this pull request to the 3.7 branch. |
…GH-8119) (cherry picked from commit 0b75228) Co-authored-by: Yury Selivanov <[email protected]>
(cherry picked from commit 0b75228) Co-authored-by: Yury Selivanov <[email protected]>
https://bugs.python.org/issue34042