Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
ericsnowcurrently wants to merge23 commits intopython:main
base:main
Choose a base branch
Loading
fromericsnowcurrently:multiple-interpreters-howto

Conversation

@ericsnowcurrently
Copy link
Member

@ericsnowcurrentlyericsnowcurrently commentedJun 30, 2025
edited by hugovk
Loading

@ericsnowcurrentlyericsnowcurrently marked this pull request as ready for reviewJune 30, 2025 23:00
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
Copy link
Contributor

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.

Copy link
MemberAuthor

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.

neonene reacted with heart emoji

if __name__ == '__main__':
interp = interpreters.create()
t = interp.call_in_thread(script)
Copy link
Contributor

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?

Copy link
MemberAuthor

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
Copy link
MemberAuthor

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This line is unused:

Suggested change
current = expected = start = None

Comment on lines +66 to +67
defwrite_example(examplesdir,name,text):
filename=os.path.join(examplesdir,f'example-{name}.py')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
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')

Comment on lines +83 to +84
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
capture_output=True,

iffailed:
print(f'{len(failed)} failed:{",".join(failed)}')
else:
print(f'all succeeded')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
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
Copy link
Member

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?

Suggested change
exclude: ^Doc/howto/multiple-interpreters-run-examples.py

Comment on lines +976 to +977
Sharing Data
------------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
SharingData
------------
Sharingdata
------------

Comment on lines +991 to +992
Using Queues
------------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
UsingQueues
------------
Usingqueues
------------

Comment on lines +1033 to +1034
Initializing Globals for a Script
---------------------------------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
InitializingGlobals for aScript
---------------------------------
Initializingglobals for ascript
---------------------------------

Comment on lines +1125 to +1126
Pipes, Sockets, etc.
--------------------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
Pipes,Sockets, etc.
--------------------
Pipes,sockets, and so on
-------------------------

Avoid Latin abbreviations:https://devguide.python.org/documentation/style-guide/#use-simple-language

Comment on lines +1272 to +1273
Tutorial: Miscellaneous
=======================
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
Tutorial:Miscellaneous
=======================
Tutorial:miscellaneous
=======================

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@hugovkhugovkhugovk left review comments

+1 more reviewer

@neoneneneoneneneonene left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

awaiting core reviewdocsDocumentation in the Doc dirneeds backport to 3.14bugs and security fixesskip news

Projects

Status: Todo

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@ericsnowcurrently@hugovk@neonene

[8]ページ先頭

©2009-2025 Movatter.jp