[3.11] gh-90876: Restore the ability to import multiprocessing when sys.executable is None (GH-106464) (#106495)

gh-90876: Restore the ability to import multiprocessing when `sys.executable` is `None` (GH-106464)

Prevent `multiprocessing.spawn` from failing to *import* in environments
where `sys.executable` is `None`.  This regressed in 3.11 with the addition
of support for path-like objects in multiprocessing.

Adds a test decorator to have tests only run when part of test_multiprocessing_spawn to `_test_multiprocessing.py` so we can start to avoid re-running the same not-global-state specific test in all 3 modes when there is no need.
(cherry picked from commit c60df361ce)

Co-authored-by: Gregory P. Smith <greg@krypto.org>
This commit is contained in:
Miss Islington (bot) 2023-07-06 16:25:20 -07:00 committed by GitHub
parent 80117dd450
commit 1931c2a438
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 83 additions and 8 deletions

View file

@ -31,11 +31,13 @@ if sys.platform != 'win32':
WINSERVICE = False
else:
WINEXE = getattr(sys, 'frozen', False)
WINSERVICE = sys.executable.lower().endswith("pythonservice.exe")
WINSERVICE = sys.executable and sys.executable.lower().endswith("pythonservice.exe")
def set_executable(exe):
global _python_exe
if sys.platform == 'win32':
if exe is None:
_python_exe = exe
elif sys.platform == 'win32':
_python_exe = os.fsdecode(exe)
else:
_python_exe = os.fsencode(exe)