@@ -699,7 +699,7 @@ index f3828b10e1..7e86539bfa 100644
699699 + _CASE_INSENSITIVE_PLATFORMS_STR_KEY)
700700
701701diff --git a/Lib/os.py b/Lib/os.py
702- index b794159f86..449cf932b6 100644
702+ index b794159f86..78aab1ea2a 100644
703703--- a/Lib/os.py
704704+++ b/Lib/os.py
705705@@ -36,7 +36,7 @@
@@ -716,7 +716,7 @@ index b794159f86..449cf932b6 100644
716716 del _fscodec
717717
718718+
719- + if sys.platform in ('iOS ', 'tvos', 'watchos'):
719+ + if sys.platform in ('ios ', 'tvos', 'watchos'):
720720+ allows_subprocesses = False
721721+ else:
722722+ allows_subprocesses = True
@@ -834,74 +834,20 @@ index 9e617afb00..41305298d3 100644
834834 return f'{userbase}/lib/python{version[0]}.{version[1]}/site-packages'
835835
836836diff --git a/Lib/subprocess.py b/Lib/subprocess.py
837- index 4effc1d8b3..70e69c2379 100644
837+ index 4effc1d8b3..b0e4a5acac 100644
838838--- a/Lib/subprocess.py
839839+++ b/Lib/subprocess.py
840- @@ -75,9 +75,13 @@
841- _mswindows = True
842- except ModuleNotFoundError:
843- _mswindows = False
844- - import _posixsubprocess
845- - import select
846- - import selectors
847- + try:
848- + import _posixsubprocess
849- + import select
850- + import selectors
851- + except ModuleNotFoundError:
852- + # iOS *has* subprocesses, but doesn't support them.
853- + _posixsubprocess = None
854- else:
855- from _winapi import (CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP,
856- STD_INPUT_HANDLE, STD_OUTPUT_HANDLE,
857- @@ -212,7 +216,7 @@
858- return "%s(%d)" % (self.__class__.__name__, int(self))
859-
860- __del__ = Close
861- - else:
862- + elif _posixsubprocess:
863- # When select or poll has indicated that the file is writable,
864- # we can write up to _PIPE_BUF bytes without risk of blocking.
865- # POSIX defines PIPE_BUF as >= 512.
866- @@ -240,7 +244,7 @@
867-
868- def _cleanup():
869- pass
870- - else:
871- + elif _posixsubprocess:
872- # This lists holds Popen instances for which the underlying process had not
873- # exited at the time its __del__ method got called: those processes are
874- # wait()ed for synchronously from _cleanup() when a new Popen object is
875- @@ -259,6 +263,9 @@
876- # This can happen if two threads create a new Popen instance.
877- # It's harmless that it was already removed, so ignore.
878- pass
879- + else:
880- + def _cleanup():
881- + pass
882-
883- PIPE = -1
884- STDOUT = -2
885- @@ -660,7 +667,7 @@
886- Prefer an implementation which can use vfork() in some cases for best
887- performance.
888- """
889- - if _mswindows or not hasattr(os, 'posix_spawn'):
890- + if _mswindows or _posixsubprocess is None or not hasattr(os, 'posix_spawn'):
891- # os.posix_spawn() is not available
892- return False
893-
894- @@ -762,6 +769,9 @@
840+ @@ -762,6 +762,9 @@
895841 pass_fds=(), *, user=None, group=None, extra_groups=None,
896842 encoding=None, errors=None, text=None, umask=-1):
897843 """Create new Popen instance."""
898- + if not _mswindows and _posixsubprocess is None :
844+ + if not os.allows_subprocesses :
899845+ raise RuntimeError(f"Subprocesses are not supported on {sys.platform}")
900846+
901847 _cleanup()
902848 # Held while anything is calling waitpid before returncode has been
903849 # updated to prevent clobbering returncode if wait() or poll() are
904- @@ -1834,7 +1844 ,7 @@
850+ @@ -1834,7 +1837 ,7 @@
905851 else:
906852 self.returncode = waitstatus_to_exitcode(sts)
907853
@@ -910,7 +856,7 @@ index 4effc1d8b3..70e69c2379 100644
910856 _WNOHANG=os.WNOHANG, _ECHILD=errno.ECHILD):
911857 """Check if child process has terminated. Returns returncode
912858 attribute.
913- @@ -1843,6 +1853 ,8 @@
859+ @@ -1843,6 +1846 ,8 @@
914860 outside of the local scope (nor can any methods it calls).
915861
916862 """
0 commit comments