Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 082d349

Browse files
authored
bpo-40280: Emscripten fork_exec now fails early (GH-32224)
1 parent 76b8a07 commit 082d349

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

Lib/subprocess.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@
9696
"CREATE_NO_WINDOW", "DETACHED_PROCESS",
9797
"CREATE_DEFAULT_ERROR_MODE", "CREATE_BREAKAWAY_FROM_JOB"])
9898
else:
99-
import _posixsubprocess
99+
if sys.platform in {"emscripten", "wasi"}:
100+
def _fork_exec(*args, **kwargs):
101+
raise OSError(
102+
errno.ENOTSUP, f"{sys.platform} does not support processes."
103+
)
104+
else:
105+
from _posixsubprocess import fork_exec as _fork_exec
100106
import select
101107
import selectors
102108

@@ -1777,7 +1783,7 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
17771783
for dir in os.get_exec_path(env))
17781784
fds_to_keep = set(pass_fds)
17791785
fds_to_keep.add(errpipe_write)
1780-
self.pid = _posixsubprocess.fork_exec(
1786+
self.pid = _fork_exec(
17811787
args, executable_list,
17821788
close_fds, tuple(sorted(map(int, fds_to_keep))),
17831789
cwd, env_list,

Lib/test/test_subprocess.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1805,7 +1805,7 @@ class PopenNoDestructor(subprocess.Popen):
18051805
def __del__(self):
18061806
pass
18071807

1808-
@mock.patch("subprocess._posixsubprocess.fork_exec")
1808+
@mock.patch("subprocess._fork_exec")
18091809
def test_exception_errpipe_normal(self, fork_exec):
18101810
"""Test error passing done through errpipe_write in the good case"""
18111811
def proper_error(*args):
@@ -1822,7 +1822,7 @@ def proper_error(*args):
18221822
with self.assertRaises(IsADirectoryError):
18231823
self.PopenNoDestructor(["non_existent_command"])
18241824

1825-
@mock.patch("subprocess._posixsubprocess.fork_exec")
1825+
@mock.patch("subprocess._fork_exec")
18261826
def test_exception_errpipe_bad_data(self, fork_exec):
18271827
"""Test error passing done through errpipe_write where its not
18281828
in the expected format"""
@@ -2112,7 +2112,7 @@ def raise_it():
21122112
preexec_fn=raise_it)
21132113
except subprocess.SubprocessError as e:
21142114
self.assertTrue(
2115-
subprocess._posixsubprocess,
2115+
subprocess._fork_exec,
21162116
"Expected a ValueError from the preexec_fn")
21172117
except ValueError as e:
21182118
self.assertIn("coconut", e.args[0])
@@ -2600,11 +2600,11 @@ def prepare():
26002600
preexec_fn=prepare)
26012601
except ValueError as err:
26022602
# Pure Python implementations keeps the message
2603-
self.assertIsNone(subprocess._posixsubprocess)
2603+
self.assertIsNone(subprocess._fork_exec)
26042604
self.assertEqual(str(err), "surrogate:\uDCff")
26052605
except subprocess.SubprocessError as err:
26062606
# _posixsubprocess uses a default message
2607-
self.assertIsNotNone(subprocess._posixsubprocess)
2607+
self.assertIsNotNone(subprocess._fork_exec)
26082608
self.assertEqual(str(err), "Exception occurred in preexec_fn.")
26092609
else:
26102610
self.fail("Expected ValueError or subprocess.SubprocessError")

configure

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

+3
Original file line numberDiff line numberDiff line change
@@ -6518,6 +6518,9 @@ AS_CASE([$ac_sys_system/$ac_sys_emscripten_target],
65186518
[_curses_panel],
65196519
[_dbm],
65206520
[_gdbm],
6521+
[_multiprocessing],
6522+
[_posixshmem],
6523+
[_posixsubprocess],
65216524
[_scproxy],
65226525
[_tkinter],
65236526
[_xxsubinterpreters],

0 commit comments

Comments
 (0)