GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||
GeezerVison is showing github.com — gh-157176: Make time.struct_time type immutable by ashm-dev · Pull Request #157179 · python/cpython Conversation
|
|
@sergey-miryanov, could you please review this PR? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
The reported issue is a leak when modifying structseq types. But this PR changes how structseq instances are tracked by the GC. Can you explain me the relationship between the two? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
They are the same bug. Modifying the type creates the cycle type -> tp_dict -> t -> type. It leaks because t is untracked, so the GC cannot see the t -> type edge. Tracking the instance makes that edge visible and lets the GC collect the cycle. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
See also #157447 change which is limited to sys.unraisablehook. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Claude initially wrote exactly this change. But it is potentially breaking, the following |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
But the fix in your PR doesn't resolve the leak from my issue. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Your both issues have a common root but fix from #157447 shouldn't fix your issue. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Friendly ping @serhiy-storchaka @vstinner — what's the plan here? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sadly, changing the public PyStructSequence_New() C API sounds dangerous. As @serhiy-storchaka wrote, it can break existing C extensions which call PyObject_GC_Track(). You can change internal C APIs or modify stdlib extensions to call PyObject_GC_Track() after PyStructSequence_New(). I'm not sure of what's the best approach. Also, if it's recommended to track objects created by |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Should I revert the PyStructSequence_New() change, add PyObject_GC_Track() to stdlib callers (time, os, etc.) similar to #157447, and document the tracking requirement in PyStructSequence_New() docs? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yes, but only add PyObject_GC_Track() if an object can contains other objects which can be involved in a reference cycle. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@vstinner Done. Reverted changes to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
# Instances created via Python or stdlib callers that may participate
# in cycles are GC-tracked; simple instances like os.stat_result are not.
self.assertTrue(gc.is_tracked(time.gmtime()))
time.gmtime() members are all integers. How can it be involved in a reference cycle?
Code from the issue:
./python -c "import time; t = time.gmtime(); type(t).refcyle = t;"
In your example, you modify the type, not a structseq instance.
I'm not sure that this change is correct.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Instead, the type should be made immutable: #157176 (comment). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
AFAIK only the argument of |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I just have a request on the test.
cc @methane
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
The Docs CI failed with: Let me update the branch to see if it does fix the issue. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I enabled auto-merged, please don't touch the PR (your branch) anymore. Thanks for |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This should be in Library.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Oh! I didn't pay attention to the section of the Changelog entry. Sadly, I saw your comment after the PR was merged.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I wrote #158983 to move it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Merged. Thanks for your fix. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.