-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-116915: Make _thread._ThreadHandle
support GC
#116934
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
Even though it has no internal references to Python objects it still has a reference to its type by virtue of being a heap type. We need to provide a traverse function that visits the type, but we do not need to provide a clear function.
Would a fix that only decrefs the type in dealloc be sufficient, without supporting GC? That could save some GC cycles. https://docs.python.org/3/c-api/typeobj.html#c.Py_TPFLAGS_HEAPTYPE |
Unfortunately, no. That decref was already present. |
The |
🤖 New build scheduled with the buildbot fleet by @colesbury for commit 2ef088d 🤖 If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again. |
Huh that's really strange. Usually cycles between types and the object itself are special. Will think about this. |
Ah right I forgot that heap types need to support GC as well. This can be seen in previous work. In this case, this LGTM. E.g. |
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.
+1. Let's wait for the refleaks builders to be become green again and then merge this.
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.
It seems there is indeed a reference cycle between heap types and the module object itself
Line 4557 in 2982bdb
res->ht_module = Py_XNewRef(module); |
Windows 11: https://buildbot.python.org/all/#/builders/1214/builds/304/steps/4/logs/stdio
cpython/Lib/test/test_threading.py Lines 424 to 459 in 2982bdb
|
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. I looked at my checkbox: https://pythondev.readthedocs.io/subinterpreters.html#convert-static-type-to-heap-type
@colesbury: I cannot reproduce the crash on Windows 11.
I stressed the test:
I tried for 15-20 minutes, without reproducing the crash :-( |
Nice fix @mpage. I confirm that it does fix the leak: #116915 (comment) |
If anyone see the test_threading.test_finalize_running_thread() crash again, please open a new issue. |
Even though it has no internal references to Python objects it still has a reference to its type by virtue of being a heap type. We need to provide a traverse function that visits the type, but we do not need to provide a clear function.
Even though it has no internal references to Python objects it still has a reference to its type by virtue of being a heap type. We need to provide a traverse function that visits the type, but we do not need to provide a clear function.
Even though it has no internal references to Python objects it still has a reference to its type by virtue of being a heap type. We need to provide a traverse function that visits the type, but we do not need to provide a clear function.
Even though it has no internal references to Python objects it still has a reference to its type by virtue of being a heap type. We need to provide a traverse function that visits the type, but we do not need to provide a clear function.
test_capi
leaks references #116915