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

Allow multiprocessing finalizers to run on a separate thread #109978

Open
pitrou opened this issue Sep 27, 2023 · 3 comments
Open

Allow multiprocessing finalizers to run on a separate thread #109978

pitrou opened this issue Sep 27, 2023 · 3 comments
Labels
topic-multiprocessing type-feature A feature request or enhancement

Comments

@pitrou
Copy link
Member

pitrou commented Sep 27, 2023

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

@pitrou pitrou added type-feature A feature request or enhancement topic-multiprocessing labels Sep 27, 2023
@pitrou
Copy link
Member Author

pitrou commented Sep 27, 2023

@vstinner FYI

@pitrou
Copy link
Member Author

pitrou commented Sep 27, 2023

@iritkatriel @pablogsal IIRC you tried to work on PEP 556 before.

@pitrou
Copy link
Member Author

pitrou commented Oct 7, 2023

Ok, I gave it a try... but, of course, the problem is that fork wreaks havoc with threads, and of course it's difficult to test multiprocessing (or concurrent.futures) without making a lot of calls to fork.

:-D

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

No branches or pull requests

1 participant