Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-134939: Add a Multiple Interpreters Howto Doc#136143
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
gh-134939: Add a Multiple Interpreters Howto Doc#136143
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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 theInterpreterPoolExecutor case, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Off-topic, but would it be possible to add thedaemon parameter to the helper method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I want to keep the helper super simple. If someone wants a daemon thread then they can do it manually without much effort.
ericsnowcurrently commentedSep 25, 2025
Any objections to merging this? |
| example=dedent(os.linesep.join(current)) | ||
| expected=''.join(f'{l}{os.linesep}'forlinexpected) | ||
| examples[start]= (example,expected) | ||
| current=expected=start=None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This line is unused:
| current = expected = start = None |
| defwrite_example(examplesdir,name,text): | ||
| filename=os.path.join(examplesdir,f'example-{name}.py') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
| stdout=subprocess.PIPE, | |
| stderr=subprocess.PIPE, | |
| capture_output=True, |
| iffailed: | ||
| print(f'{len(failed)} failed:{",".join(failed)}') | ||
| else: | ||
| print(f'all succeeded') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
| SharingData | |
| ------------ | |
| Sharingdata | |
| ------------ |
| Using Queues | ||
| ------------ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
| UsingQueues | |
| ------------ | |
| Usingqueues | |
| ------------ |
| Initializing Globals for a Script | ||
| --------------------------------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
| InitializingGlobals for aScript | |
| --------------------------------- | |
| Initializingglobals for ascript | |
| --------------------------------- |
| Pipes, Sockets, etc. | ||
| -------------------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
| Tutorial:Miscellaneous | |
| ======================= | |
| Tutorial:miscellaneous | |
| ======================= |
Uh oh!
There was an error while loading.Please reload this page.
📚 Documentation preview 📚:https://cpython-previews--136143.org.readthedocs.build/en/136143/howto/multiple-interpreters.html#multiple-interpreters-howto