Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed
wants to merge 4 commits into from

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Sep 2, 2019

@pablogsal
Copy link
Member Author

pablogsal commented Sep 2, 2019

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;
Copy link
Member

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?

Copy link
Member Author

@pablogsal pablogsal Sep 16, 2019

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?

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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.

@pablogsal pablogsal requested a review from Yhg1s September 16, 2019 20:18
@pablogsal
Copy link
Member Author

I think I am closing this now that #16495 is merged, as I agree is a more resilient solution.

@pablogsal pablogsal closed this Oct 8, 2019
@pablogsal pablogsal deleted the bpo-38009 branch May 19, 2021 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants