-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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
bpo-46720: Add support for path-like objects to multiprocessing.set_executable for Windows to be on a par with Unix-like systems #31279
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
eryksun
reviewed
Feb 11, 2022
eryksun
reviewed
Feb 11, 2022
eryksun
reviewed
Feb 11, 2022
Thanks for the review @eryksun, I have also updated the documentation and added a news entry. |
@brettcannon, since you coauthored PEP 519, can I request your review of this PR? |
Do we need an explicit test for this? |
@brettcannon Yes, I think so. I have just added one. |
brettcannon
approved these changes
Apr 22, 2022
Thanks for the review @brettcannon! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On Unix-like systems, the function
multiprocessing.set_executable
accepts any path-like objects (str
,bytes
, andos.PathLike
) as itsexecutable
argument for setting up the path to the Python interpretermultiprocessing.spawn._python_exe
.For instance these work (tested on MacOS with all start methods: ‘spawn’, ‘fork’, and ‘forkserver’):
multiprocessing.set_executable(sys.executable)
(str
);multiprocessing.set_executable(sys.executable.encode())
(bytes
);multiprocessing.set_executable(pathlib.Path(sys.executable))
(os.PathLike
).This is because
the ‘fork’ start method does not execute any program in the child process;
the ‘spawn’ start method converts
multiprocessing.spawn._python_exe
tobytes
withos.fsencode
before passing it to the function_posixsubprocess.fork_exec
to create a child process, andbytes
is the expectedargv
argument type:the ‘forkserver’ start method spawns a server process (like with the ‘spawn’ start method) which then forks itself at each request (like the ‘fork’ start method).
But on Windows, the ‘spawn’ start method (the only start method available on this O.S.) does not convert
multiprocessing.spawn._python_exe
tostr
withos.fsdecode
before passing it to the function_winapi.CreateProcess
to create a child process, whereasstr
is the expectedapplication_name
argument type:So on Windows the function
multiprocessing.set_executable
accepts onlystr
objects as itsexecutable
argument. This pull request fixes this to be on a par with Unix-like systems for which the function accepts any path-like objects.https://bugs.python.org/issue46720