bpo-40280: Emscripten fork_exec now fails early (GH-32224)

This commit is contained in:
Christian Heimes 2022-04-01 22:20:56 +03:00 committed by GitHub
parent 76b8a075b8
commit 082d3495d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 7 deletions

View File

@ -96,7 +96,13 @@ if _mswindows:
"CREATE_NO_WINDOW", "DETACHED_PROCESS",
"CREATE_DEFAULT_ERROR_MODE", "CREATE_BREAKAWAY_FROM_JOB"])
else:
import _posixsubprocess
if sys.platform in {"emscripten", "wasi"}:
def _fork_exec(*args, **kwargs):
raise OSError(
errno.ENOTSUP, f"{sys.platform} does not support processes."
)
else:
from _posixsubprocess import fork_exec as _fork_exec
import select
import selectors
@ -1777,7 +1783,7 @@ class Popen:
for dir in os.get_exec_path(env))
fds_to_keep = set(pass_fds)
fds_to_keep.add(errpipe_write)
self.pid = _posixsubprocess.fork_exec(
self.pid = _fork_exec(
args, executable_list,
close_fds, tuple(sorted(map(int, fds_to_keep))),
cwd, env_list,

View File

@ -1805,7 +1805,7 @@ class POSIXProcessTestCase(BaseTestCase):
def __del__(self):
pass
@mock.patch("subprocess._posixsubprocess.fork_exec")
@mock.patch("subprocess._fork_exec")
def test_exception_errpipe_normal(self, fork_exec):
"""Test error passing done through errpipe_write in the good case"""
def proper_error(*args):
@ -1822,7 +1822,7 @@ class POSIXProcessTestCase(BaseTestCase):
with self.assertRaises(IsADirectoryError):
self.PopenNoDestructor(["non_existent_command"])
@mock.patch("subprocess._posixsubprocess.fork_exec")
@mock.patch("subprocess._fork_exec")
def test_exception_errpipe_bad_data(self, fork_exec):
"""Test error passing done through errpipe_write where its not
in the expected format"""
@ -2112,7 +2112,7 @@ class POSIXProcessTestCase(BaseTestCase):
preexec_fn=raise_it)
except subprocess.SubprocessError as e:
self.assertTrue(
subprocess._posixsubprocess,
subprocess._fork_exec,
"Expected a ValueError from the preexec_fn")
except ValueError as e:
self.assertIn("coconut", e.args[0])
@ -2600,11 +2600,11 @@ class POSIXProcessTestCase(BaseTestCase):
preexec_fn=prepare)
except ValueError as err:
# Pure Python implementations keeps the message
self.assertIsNone(subprocess._posixsubprocess)
self.assertIsNone(subprocess._fork_exec)
self.assertEqual(str(err), "surrogate:\uDCff")
except subprocess.SubprocessError as err:
# _posixsubprocess uses a default message
self.assertIsNotNone(subprocess._posixsubprocess)
self.assertIsNotNone(subprocess._fork_exec)
self.assertEqual(str(err), "Exception occurred in preexec_fn.")
else:
self.fail("Expected ValueError or subprocess.SubprocessError")

3
configure generated vendored
View File

@ -21772,6 +21772,9 @@ case $ac_sys_system/$ac_sys_emscripten_target in #(
py_cv_module__curses_panel=n/a
py_cv_module__dbm=n/a
py_cv_module__gdbm=n/a
py_cv_module__multiprocessing=n/a
py_cv_module__posixshmem=n/a
py_cv_module__posixsubprocess=n/a
py_cv_module__scproxy=n/a
py_cv_module__tkinter=n/a
py_cv_module__xxsubinterpreters=n/a

View File

@ -6518,6 +6518,9 @@ AS_CASE([$ac_sys_system/$ac_sys_emscripten_target],
[_curses_panel],
[_dbm],
[_gdbm],
[_multiprocessing],
[_posixshmem],
[_posixsubprocess],
[_scproxy],
[_tkinter],
[_xxsubinterpreters],