Skip to content

Commit 8184f0f

Browse files
authored
gh-95174: Handle missing waitpid and gethostbyname in WASI (GH-95181)
1 parent 5c7f3bc commit 8184f0f

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

Lib/subprocess.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,19 @@
102102
else:
103103
if _can_fork_exec:
104104
from _posixsubprocess import fork_exec as _fork_exec
105+
# used in methods that are called by __del__
106+
_waitpid = os.waitpid
107+
_waitstatus_to_exitcode = os.waitstatus_to_exitcode
108+
_WIFSTOPPED = os.WIFSTOPPED
109+
_WSTOPSIG = os.WSTOPSIG
110+
_WNOHANG = os.WNOHANG
105111
else:
106112
_fork_exec = None
113+
_waitpid = None
114+
_waitstatus_to_exitcode = None
115+
_WIFSTOPPED = None
116+
_WSTOPSIG = None
117+
_WNOHANG = None
107118
import select
108119
import selectors
109120

@@ -1890,19 +1901,19 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
18901901

18911902

18921903
def _handle_exitstatus(self, sts,
1893-
waitstatus_to_exitcode=os.waitstatus_to_exitcode,
1894-
_WIFSTOPPED=os.WIFSTOPPED,
1895-
_WSTOPSIG=os.WSTOPSIG):
1904+
_waitstatus_to_exitcode=_waitstatus_to_exitcode,
1905+
_WIFSTOPPED=_WIFSTOPPED,
1906+
_WSTOPSIG=_WSTOPSIG):
18961907
"""All callers to this function MUST hold self._waitpid_lock."""
18971908
# This method is called (indirectly) by __del__, so it cannot
18981909
# refer to anything outside of its local scope.
18991910
if _WIFSTOPPED(sts):
19001911
self.returncode = -_WSTOPSIG(sts)
19011912
else:
1902-
self.returncode = waitstatus_to_exitcode(sts)
1913+
self.returncode = _waitstatus_to_exitcode(sts)
19031914

1904-
def _internal_poll(self, _deadstate=None, _waitpid=os.waitpid,
1905-
_WNOHANG=os.WNOHANG, _ECHILD=errno.ECHILD):
1915+
def _internal_poll(self, _deadstate=None, _waitpid=_waitpid,
1916+
_WNOHANG=_WNOHANG, _ECHILD=errno.ECHILD):
19061917
"""Check if child process has terminated. Returns returncode
19071918
attribute.
19081919

Lib/uuid.py

+2
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ def _ip_getnode():
524524
def _arp_getnode():
525525
"""Get the hardware address on Unix by running arp."""
526526
import os, socket
527+
if not hasattr(socket, "gethostbyname"):
528+
return None
527529
try:
528530
ip_addr = socket.gethostbyname(socket.gethostname())
529531
except OSError:

0 commit comments

Comments
 (0)