bpo-38009: Do not call weakref callbacks that are being collected#15645
bpo-38009: Do not call weakref callbacks that are being collected#15645pablogsal wants to merge 4 commits into
Conversation
|
I will change the PR to add a warning and fix the comment explaining the problem and add some tests if I manage to reproduce it. |
| " was triying to execute a callback to a function that is being cleared by" | ||
| " the garbage collector.\n Some C extension class in the dependence" | ||
| " chain is probably not implementing correctly the garbage collector support.", 1); | ||
| return; |
There was a problem hiding this comment.
What is the actual effect of just returning here? The callback isn't being called, but it wouldn't have been called had all the objects in the cycle had done the right thing, right? So what's the actual value of the warning?
There was a problem hiding this comment.
So what's the actual value of the warning?
The reason we return is to not crash and then we warn that the interpreter has avoided a crash due to a bad implementation but we need to issue the warning so this does not pass silently.
Would you prefer to just crash?
There was a problem hiding this comment.
No, I'm trying to find out if there are other reasons that people should fix their code, besides the specific crash that you're now turning into a warning. If the only reason to fix the code is to avoid this warning, the warning just becomes noise -- especially because very often the warning isn't seen by the developer responsible for the incorrect C code, but some helpless user.
There was a problem hiding this comment.
Oh, I understand. Well, after this fix there is no hard crash, but an incorrect implementation of the garbage collector can have undefined consequences. These range from leaks because tp_traverse is not correctly implemented or some other crashes elsewhere.
What do you think we should do here? Maybe a more comprehensive message?
There was a problem hiding this comment.
I'm thinking less of a message, really :) The message is useful for people who have control over the C code that does the wrong thing, but to end users of the module. Maybe the exception should be a DeprecationWarning, so it's not shown by default? Perhaps we should discuss this on python-dev or discourse.
|
I think I am closing this now that #16495 is merged, as I agree is a more resilient solution. |
https://bugs.python.org/issue38009