Uh oh!
There was an error while loading. Please reload this page.
gh-134939: Add a Multiple Interpreters Howto Doc - #136143
gh-134939: Add a Multiple Interpreters Howto Doc#136143ericsnowcurrently wants to merge 23 commits into
Conversation
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: neonene <53406459+neonene@users.noreply.github.com>
| are still relatively inefficient and limited | ||
| * actually *sharing* data safely is tricky (true for free-threading too) | ||
| * all necessary modules must be imported separately in each interpreter | ||
| * relatively slow startup time per interpreter |
There was a problem hiding this comment.
Some users might need a (foot)note that subinterpreters can sometimes improve the startup by importing nothing.
example
defnon_stateless():
non_statelessif__name__=='__main__':
importthreadingfromconcurrentimportinterpretersinterps= [interpreters.create() foriinrange(10)]
threads= [
threading.Thread(target=interp.call, args=(non_stateless,))
forinterpininterps
]
forthreadinthreads:
thread.start()
forthreadinthreads:
thread.join()That seems not so beneficial for the InterpreterPoolExecutor case, though.
There was a problem hiding this comment.
I've added a note, though further down in the discussion about calling functions.
| if __name__ == '__main__': | ||
| interp = interpreters.create() | ||
| t = interp.call_in_thread(script) |
There was a problem hiding this comment.
Off-topic, but would it be possible to add the daemon parameter to the helper method?
There was a problem hiding this comment.
I want to keep the helper super simple. If someone wants a daemon thread then they can do it manually without much effort.
ericsnowcurrently
commented
Sep 25, 2025
Any objections to merging this? |
| example = dedent(os.linesep.join(current)) | ||
| expected = ''.join(f'{l}{os.linesep}' for l in expected) | ||
| examples[start] = (example, expected) | ||
| current = expected = start = None |
There was a problem hiding this comment.
This line is unused:
| current = expected = start = None |
| def write_example(examplesdir, name, text): | ||
| filename = os.path.join(examplesdir, f'example-{name}.py') |
There was a problem hiding this comment.
| defwrite_example(examplesdir, name, text): | |
| filename=os.path.join(examplesdir, f'example-{name}.py') | |
| defwrite_example(examples_dir, name, text): | |
| filename=os.path.join(examples_dir, f'example-{name}.py') |
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE, |
There was a problem hiding this comment.
| stdout=subprocess.PIPE, | |
| stderr=subprocess.PIPE, | |
| capture_output=True, |
| if failed: | ||
| print(f'{len(failed)} failed: {",".join(failed)}') | ||
| else: | ||
| print(f'all succeeded') |
There was a problem hiding this comment.
| print(f'all succeeded') | |
| print('all succeeded') |
| name: Run Ruff (lint) on Doc/ | ||
| args: [--exit-non-zero-on-fix] | ||
| files: ^Doc/ | ||
| exclude: ^Doc/howto/multiple-interpreters-run-examples.py |
There was a problem hiding this comment.
Let's remove these exclusions and do the fixes?
| exclude: ^Doc/howto/multiple-interpreters-run-examples.py |
| Sharing Data | ||
| ------------ |
There was a problem hiding this comment.
| Sharing Data | |
| ------------ | |
| Sharing data | |
| ------------ |
| Using Queues | ||
| ------------ |
There was a problem hiding this comment.
| Using Queues | |
| ------------ | |
| Using queues | |
| ------------ |
| Initializing Globals for a Script | ||
| --------------------------------- |
There was a problem hiding this comment.
| Initializing Globals for a Script | |
| --------------------------------- | |
| Initializing globals for a script | |
| --------------------------------- |
| Pipes, Sockets, etc. | ||
| -------------------- |
There was a problem hiding this comment.
| Pipes, Sockets, etc. | |
| -------------------- | |
| Pipes, sockets, and so on | |
| ------------------------- |
Avoid Latin abbreviations: https://devguide.python.org/documentation/style-guide/#use-simple-language
| Tutorial: Miscellaneous | ||
| ======================= |
There was a problem hiding this comment.
| Tutorial: Miscellaneous | |
| ======================= | |
| Tutorial: miscellaneous | |
| ======================= |
This PR is stale because it has been open for 30 days with no activity. |
📚 Documentation preview 📚: https://cpython-previews--136143.org.readthedocs.build/en/136143/howto/multiple-interpreters.html#multiple-interpreters-howto