-
- Notifications
You must be signed in to change notification settings - Fork 32.3k
Replace weakref to the _WeakValueDictionary with strong ref to outlives keys #136345
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
!buildbot refleak* |
You don't have write permissions to trigger a build |
🤖 New build scheduled with the buildbot fleet by @sobolevn for commit c30038d 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F136345%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again. |
Can you add the issue this pr tries to solve? just for triaging purposes |
I don't know what code you are trying. Can you show the leak-reproducible code here I'm mainly using these tests: #136189 (comment). |
Following diff fixes leaks on 12f0b5c for
Result
|
I presume that the cycles weren't handled well. But don't know how to debug this on C-level. |
@neonene on 12f0b5c I got following simpler repro from yours
But it doesn't leak on main. Along last changes from Neil I'm not sure it is worth investigating further for 12f0b5c. |
Inspired by your great version: import weakref, _interpreters wd = weakref.WeakValueDictionary() class TestInterpreterCall(unittest.TestCase): def test_call_in_thread_XXX(self): id = _interpreters.create() wd[id] = type("", (), {}) _interpreters.destroy(id) Refleak bots usually pass full tests on main, so our just simplified repros cannot leak there. The repros leak only when weakrefs with a callback are cleared later on our PRs. Ideally (if possible), we should try to fix such leaks on C-level to not distinguish what weakref is cleared earlier/later, I think. |
With this change (applied to last #136189)
Yours Testing full tests set now... |
There is no leak in the current PR as-is. @@ -923,3 +923,3 @@ // finalizers have been called fixes that bug. - if (wr->wr_callback != NULL) { + if (0) { // _PyWeakref_ClearRef clears the weakref but leaves the |
Following change fixes our examples:
But |
No description provided.