[Python-checkins] gh-95174: Handle missing waitpid and gethostbyname in WASI (GH-95181)
miss-islington
webhook-mailer at python.org
Sun Jul 24 02:30:46 EDT 2022
https://github.com/python/cpython/commit/00cda6b530a5718f17e286da72aa4a743ada63a6
commit: 00cda6b530a5718f17e286da72aa4a743ada63a6
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-07-23T23:30:39-07:00
summary:
gh-95174: Handle missing waitpid and gethostbyname in WASI (GH-95181)
(cherry picked from commit 8184f0fce3b734413e3d3a282f1425d3cb8507fd)
Co-authored-by: Christian Heimes <christian at python.org>
files:
M Lib/subprocess.py
M Lib/uuid.py
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index e10b01047ebef..7ae8df154b481 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -102,8 +102,19 @@
else:
if _can_fork_exec:
from _posixsubprocess import fork_exec as _fork_exec
+ # used in methods that are called by __del__
+ _waitpid = os.waitpid
+ _waitstatus_to_exitcode = os.waitstatus_to_exitcode
+ _WIFSTOPPED = os.WIFSTOPPED
+ _WSTOPSIG = os.WSTOPSIG
+ _WNOHANG = os.WNOHANG
else:
_fork_exec = None
+ _waitpid = None
+ _waitstatus_to_exitcode = None
+ _WIFSTOPPED = None
+ _WSTOPSIG = None
+ _WNOHANG = None
import select
import selectors
@@ -1890,19 +1901,19 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
def _handle_exitstatus(self, sts,
- waitstatus_to_exitcode=os.waitstatus_to_exitcode,
- _WIFSTOPPED=os.WIFSTOPPED,
- _WSTOPSIG=os.WSTOPSIG):
+ _waitstatus_to_exitcode=_waitstatus_to_exitcode,
+ _WIFSTOPPED=_WIFSTOPPED,
+ _WSTOPSIG=_WSTOPSIG):
"""All callers to this function MUST hold self._waitpid_lock."""
# This method is called (indirectly) by __del__, so it cannot
# refer to anything outside of its local scope.
if _WIFSTOPPED(sts):
self.returncode = -_WSTOPSIG(sts)
else:
- self.returncode = waitstatus_to_exitcode(sts)
+ self.returncode = _waitstatus_to_exitcode(sts)
- def _internal_poll(self, _deadstate=None, _waitpid=os.waitpid,
- _WNOHANG=os.WNOHANG, _ECHILD=errno.ECHILD):
+ def _internal_poll(self, _deadstate=None, _waitpid=_waitpid,
+ _WNOHANG=_WNOHANG, _ECHILD=errno.ECHILD):
"""Check if child process has terminated. Returns returncode
attribute.
diff --git a/Lib/uuid.py b/Lib/uuid.py
index f179d68e8265a..8fe2479f3f22c 100644
--- a/Lib/uuid.py
+++ b/Lib/uuid.py
@@ -524,6 +524,8 @@ def _ip_getnode():
def _arp_getnode():
"""Get the hardware address on Unix by running arp."""
import os, socket
+ if not hasattr(socket, "gethostbyname"):
+ return None
try:
ip_addr = socket.gethostbyname(socket.gethostname())
except OSError:
More information about the Python-checkins
mailing list