Skip to content
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

gh-90876: Restore the ability to import multiprocessing when sys.executable is None #106464

Merged
merged 9 commits into from
Jul 6, 2023

Conversation

gpshead
Copy link
Member

@gpshead gpshead commented Jul 5, 2023

We could at least import multiprocessing when sys.executable == None (embedded things for example) in the past, this regressed in 3.11. This restores the ability to import it. (obviously spawn and forkserver won't work as is in that environment, but the imports need to work to allow code to construct a workaround for this)

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

@Yhg1s Yhg1s left a comment

Choose a reason for hiding this comment

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

There's another unguarded use of sys.executable in spawn.py, causing a test failure on Windows:

File "D:\a\cpython\cpython\Lib\multiprocessing\spawn.py", line 34, in
WINSERVICE = sys.executable.lower().endswith("pythonservice.exe")
^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'lower'

Lib/test/_test_multiprocessing.py Outdated Show resolved Hide resolved
@gpshead gpshead self-assigned this Jul 6, 2023
@gpshead gpshead enabled auto-merge (squash) July 6, 2023 22:27
@gpshead gpshead merged commit c60df36 into python:main Jul 6, 2023
@miss-islington
Copy link
Contributor

Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 6, 2023
…ys.executable` is `None` (pythonGH-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 c60df36)

Co-authored-by: Gregory P. Smith <greg@krypto.org>
@bedevere-bot
Copy link

GH-106494 is a backport of this pull request to the 3.12 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.12 bug and security fixes label Jul 6, 2023
@bedevere-bot
Copy link

GH-106495 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Jul 6, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 6, 2023
…ys.executable` is `None` (pythonGH-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 c60df36)

Co-authored-by: Gregory P. Smith <greg@krypto.org>
@gpshead gpshead deleted the multiprocessing_sys_executable_none branch July 6, 2023 23:24
gpshead added a commit that referenced this pull request Jul 6, 2023
…sys.executable` is `None` (GH-106464) (#106494)

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 c60df36)

Co-authored-by: Gregory P. Smith <greg@krypto.org>
gpshead added a commit that referenced this pull request Jul 6, 2023
…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 c60df36)

Co-authored-by: Gregory P. Smith <greg@krypto.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants