Skip to content
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

Defer functions defined in nested classes in free-threaded builds #127274

Open
mpage opened this issue Nov 25, 2024 · 0 comments
Open

Defer functions defined in nested classes in free-threaded builds #127274

mpage opened this issue Nov 25, 2024 · 0 comments
Labels
topic-free-threading type-feature A feature request or enhancement

Comments

@mpage
Copy link
Contributor

mpage commented Nov 25, 2024

Feature or enhancement

Proposal:

We currently only defer functions that do not have the CO_NESTED flag set:

if ((code_obj->co_flags & CO_NESTED) == 0) {
// Use deferred reference counting for top-level functions, but not
// nested functions because they are more likely to capture variables,
// which makes prompt deallocation more important.
_PyObject_SetDeferredRefcount((PyObject *)op);
}

This also excludes functions defined on nested classes. In the example below, the Foo.__init__ function will not use deferred reference counting because the __init__ method's code object has the CO_NESTED flag set.

def func():
    class Foo:
        def __init__(self):
            pass

We would like to relax the restriction on CO_NESTED to allow functions that are defined on nested classes to use deferred reference counting.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-free-threading type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant