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

Add concurrent.futures.InterpreterPoolExecutor #124694

Closed
ericsnowcurrently opened this issue Sep 27, 2024 · 0 comments
Closed

Add concurrent.futures.InterpreterPoolExecutor #124694

ericsnowcurrently opened this issue Sep 27, 2024 · 0 comments
Assignees
Labels
3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir topic-subinterpreters type-feature A feature request or enhancement

Comments

@ericsnowcurrently
Copy link
Member

ericsnowcurrently commented Sep 27, 2024

Feature or enhancement

Proposal:

While we wait on PEP 734, there's nothing blocking us from adding a new executor for multiple interpreters. Doing so would allow people to start trying them out. (I wish I had thought of this for 3.13!)

My planned design:

  • mostly built on top of ThreadPoolExecutor
  • callables (and args) passed as initializer or to submit() or map() will be pickled (same as ProcessPoolExecutor)
  • initializer and submit() arg can be a script instead of a callable (a script for map() doesn't make sense since there are no args)
  • __init__() will take a new "shared" arg that corresponds to what Interpreter.prepare_main() takes in PEP 734, to allow each worker interpreter to share some data

In the future we could support a more efficient "sharing" scheme than pickle. When (or if) PEP 734 is accepted, we can refactor the executor to use the interpreters module rather than using _interpreters directly.

Open questions:

  • reconstitute and raise uncaught exceptions from running in the interpreter (like we do for ProcessPoolExecutor)?
  • (optionally?) exec functions against main instead of the their original module, i.e. use the body of the function as a script?

CC @brianquinlan

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

@ericsnowcurrently ericsnowcurrently added type-feature A feature request or enhancement stdlib Python modules in the Lib dir topic-subinterpreters 3.14 new features, bugs and security fixes labels Sep 27, 2024
@ericsnowcurrently ericsnowcurrently self-assigned this Sep 27, 2024
ericsnowcurrently added a commit that referenced this issue Oct 16, 2024
This is an implementation of InterpreterPoolExecutor that builds on ThreadPoolExecutor.

(Note that this is not tied to PEP 734, which is strictly about adding a new stdlib module.)

Possible future improvements:

* support passing a script for the initializer or to submit()
* support passing (most) arbitrary functions without pickling
* support passing closures
* optionally exec functions against __main__ instead of the their original module
@github-project-automation github-project-automation bot moved this from Todo to Done in Subinterpreters Oct 16, 2024
ericsnowcurrently added a commit that referenced this issue Oct 18, 2024
…olicy During Cleanup (gh-125708)

This resolves a failure on the android buildbot.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir topic-subinterpreters type-feature A feature request or enhancement
Projects
Status: Done
Development

No branches or pull requests

1 participant