-
-
Notifications
You must be signed in to change notification settings - Fork 32k
PyObject_CallFinalizerFromDealloc is not referenced in any documentation #78090
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
Comments
PEP-442 states that:
But it does not give the names of these functions, nor do any python docs I can discover. From grepping for tp_finalize, it seems the functions in question are:
It would be great if these could be documented, and perhaps even an example given of when it's appropriate to call each one. |
I think I can describe what two function does/for. --- "Finalizer" is __del__ in Python and tp_finalize in C. Calling finalizer requires some tricks, including avoiding call twice. But finalizer is called from destructor (tp_dealloc) usually, and calling finalizer from destructor need more hack (e.g. temporary increment refcount). This is what PyObject_CallFinalizerFromDealloc does. Generally speaking, this API is used only when you want to use both of custom tp_dealloc and tp_finalize. This is very rare because you can write cleanup code in tp_dealloc and skip using tp_finalize. When you need really need both of tp_dealloc and tp_finalize, note that:
This is tp_dealloc of Future object in asyncio. This object uses both of tp_dealloc and tp_finalize for compatibility with Future object implemented in pure Python. This covers many edge cases of tp_dealloc.
|
Duplicate of #75459 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: