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
@@ -1958,20 +1962,16 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
1958
1962
raise child_exception_type (err_msg )
1959
1963
1960
1964
1961
- def _handle_exitstatus (self , sts ,
1962
- _waitstatus_to_exitcode = _waitstatus_to_exitcode ,
1963
- _WIFSTOPPED = _WIFSTOPPED ,
1964
- _WSTOPSIG = _WSTOPSIG ):
1965
+ def _handle_exitstatus (self , sts , _del_safe = _del_safe ):
1965
1966
"""All callers to this function MUST hold self._waitpid_lock."""
1966
1967
# This method is called (indirectly) by __del__, so it cannot
1967
1968
# refer to anything outside of its local scope.
1968
- if _WIFSTOPPED (sts ):
1969
- self .returncode = - _WSTOPSIG (sts )
1969
+ if _del_safe . WIFSTOPPED (sts ):
1970
+ self .returncode = - _del_safe . WSTOPSIG (sts )
1970
1971
else :
1971
- self .returncode = _waitstatus_to_exitcode (sts )
1972
+ self .returncode = _del_safe . waitstatus_to_exitcode (sts )
1972
1973
1973
- def _internal_poll (self , _deadstate = None , _waitpid = _waitpid ,
1974
- _WNOHANG = _WNOHANG , _ECHILD = errno .ECHILD ):
1974
+ def _internal_poll (self , _deadstate = None , _del_safe = _del_safe ):
1975
1975
"""Check if child process has terminated. Returns returncode
1976
1976
attribute.
1977
1977
@@ -1987,13 +1987,13 @@ def _internal_poll(self, _deadstate=None, _waitpid=_waitpid,
1987
1987
try :
1988
1988
if self .returncode is not None :
1989
1989
return self .returncode # Another thread waited.
1990
- pid , sts = _waitpid (self .pid , _WNOHANG )
1990
+ pid , sts = _del_safe . waitpid (self .pid , _del_safe . WNOHANG )
1991
1991
if pid == self .pid :
1992
1992
self ._handle_exitstatus (sts )
1993
1993
except OSError as e :
1994
1994
if _deadstate is not None :
1995
1995
self .returncode = _deadstate
1996
- elif e .errno == _ECHILD :
1996
+ elif e .errno == _del_safe . ECHILD :
1997
1997
# This happens if SIGCLD is set to be ignored or
1998
1998
# waiting for child processes has otherwise been
1999
1999
# disabled for our process. This child is dead, we
0 commit comments