Skip to content

Allow multiprocessing finalizers to run on a separate thread #109978

Open
@pitrou

Description

@pitrou

Feature or enhancement

Proposal:

The multiprocessing library allows finalizers to be attached to specific objects, so as to release system resources. These finalizers may have non-trivial code that rely on and alter global state.

Unfortunately, since mainline code can be interrupted at any time by the GC, there can be rare reentrancy issues with such non-trivial finalizers, such as in gh-109593.

Ideally, we would run such finalizers in a separate thread rather than from inside the GC.

Note this is related to https://peps.python.org/pep-0556/, but much more focussed and therefore with a higher chance of success.

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

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions