74
74
else :
75
75
_mswindows = True
76
76
77
- # wasm32-emscripten and wasm32-wasi do not support processes
78
- _can_fork_exec = sys .platform not in {"emscripten" , "wasi" }
77
+ # some platforms do not support subprocesses
78
+ _can_fork_exec = sys .platform not in {"emscripten" , "wasi" , "ios" , "tvos" , "watchos" }
79
79
80
80
if _mswindows :
81
81
import _winapi
103
103
if _can_fork_exec :
104
104
from _posixsubprocess import fork_exec as _fork_exec
105
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
106
+ class _del_safe :
107
+ waitpid = os .waitpid
108
+ waitstatus_to_exitcode = os .waitstatus_to_exitcode
109
+ WIFSTOPPED = os .WIFSTOPPED
110
+ WSTOPSIG = os .WSTOPSIG
111
+ WNOHANG = os .WNOHANG
112
+ ECHILD = errno .ECHILD
111
113
else :
112
- _fork_exec = None
113
- _waitpid = None
114
- _waitstatus_to_exitcode = None
115
- _WIFSTOPPED = None
116
- _WSTOPSIG = None
117
- _WNOHANG = None
114
+ class _del_safe :
115
+ waitpid = None
116
+ waitstatus_to_exitcode = None
117
+ WIFSTOPPED = None
118
+ WSTOPSIG = None
119
+ WNOHANG = None
120
+ ECHILD = errno .ECHILD
121
+
118
122
import select
119
123
import selectors
120
124
@@ -1951,20 +1955,16 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
1951
1955
raise child_exception_type (err_msg )
1952
1956
1953
1957
1954
- def _handle_exitstatus (self , sts ,
1955
- _waitstatus_to_exitcode = _waitstatus_to_exitcode ,
1956
- _WIFSTOPPED = _WIFSTOPPED ,
1957
- _WSTOPSIG = _WSTOPSIG ):
1958
+ def _handle_exitstatus (self , sts , _del_safe = _del_safe ):
1958
1959
"""All callers to this function MUST hold self._waitpid_lock."""
1959
1960
# This method is called (indirectly) by __del__, so it cannot
1960
1961
# refer to anything outside of its local scope.
1961
- if _WIFSTOPPED (sts ):
1962
- self .returncode = - _WSTOPSIG (sts )
1962
+ if _del_safe . WIFSTOPPED (sts ):
1963
+ self .returncode = - _del_safe . WSTOPSIG (sts )
1963
1964
else :
1964
- self .returncode = _waitstatus_to_exitcode (sts )
1965
+ self .returncode = _del_safe . waitstatus_to_exitcode (sts )
1965
1966
1966
- def _internal_poll (self , _deadstate = None , _waitpid = _waitpid ,
1967
- _WNOHANG = _WNOHANG , _ECHILD = errno .ECHILD ):
1967
+ def _internal_poll (self , _deadstate = None , _del_safe = _del_safe ):
1968
1968
"""Check if child process has terminated. Returns returncode
1969
1969
attribute.
1970
1970
@@ -1980,13 +1980,13 @@ def _internal_poll(self, _deadstate=None, _waitpid=_waitpid,
1980
1980
try :
1981
1981
if self .returncode is not None :
1982
1982
return self .returncode # Another thread waited.
1983
- pid , sts = _waitpid (self .pid , _WNOHANG )
1983
+ pid , sts = _del_safe . waitpid (self .pid , _del_safe . WNOHANG )
1984
1984
if pid == self .pid :
1985
1985
self ._handle_exitstatus (sts )
1986
1986
except OSError as e :
1987
1987
if _deadstate is not None :
1988
1988
self .returncode = _deadstate
1989
- elif e .errno == _ECHILD :
1989
+ elif e .errno == _del_safe . ECHILD :
1990
1990
# This happens if SIGCLD is set to be ignored or
1991
1991
# waiting for child processes has otherwise been
1992
1992
# disabled for our process. This child is dead, we
0 commit comments