-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
bpo-38009: Do not call weakref callbacks that are being collected #15645
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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