Commit a7e988d5 authored by Jason Madden's avatar Jason Madden

fix defaults for close_fds on windows

parent 3fb4d1e4
...@@ -295,12 +295,13 @@ else: ...@@ -295,12 +295,13 @@ else:
raise ex raise ex
return output return output
_PLATFORM_DEFAULT_CLOSE_FDS = object()
class Popen(object): class Popen(object):
def __init__(self, args, bufsize=None, executable=None, def __init__(self, args, bufsize=None, executable=None,
stdin=None, stdout=None, stderr=None, stdin=None, stdout=None, stderr=None,
preexec_fn=None, close_fds=None, shell=False, preexec_fn=None, close_fds=_PLATFORM_DEFAULT_CLOSE_FDS, shell=False,
cwd=None, env=None, universal_newlines=False, cwd=None, env=None, universal_newlines=False,
startupinfo=None, creationflags=0, threadpool=None, startupinfo=None, creationflags=0, threadpool=None,
**kwargs): **kwargs):
...@@ -323,19 +324,18 @@ class Popen(object): ...@@ -323,19 +324,18 @@ class Popen(object):
if not isinstance(bufsize, integer_types): if not isinstance(bufsize, integer_types):
raise TypeError("bufsize must be an integer") raise TypeError("bufsize must be an integer")
if close_fds is None:
# close_fds has different defaults on Py3/Py2
if PY3:
close_fds = True
else:
close_fds = False
if mswindows: if mswindows:
if preexec_fn is not None: if preexec_fn is not None:
raise ValueError("preexec_fn is not supported on Windows " raise ValueError("preexec_fn is not supported on Windows "
"platforms") "platforms")
if close_fds and (stdin is not None or stdout is not None or any_stdio_set = (stdin is not None or stdout is not None or
stderr is not None): stderr is not None)
if close_fds is _PLATFORM_DEFAULT_CLOSE_FDS:
if any_stdio_set:
close_fds = False
else:
close_fds = True
elif close_fds and any_stdio_set:
raise ValueError("close_fds is not supported on Windows " raise ValueError("close_fds is not supported on Windows "
"platforms if you redirect stdin/stdout/stderr") "platforms if you redirect stdin/stdout/stderr")
if threadpool is None: if threadpool is None:
...@@ -344,6 +344,13 @@ class Popen(object): ...@@ -344,6 +344,13 @@ class Popen(object):
self._waiting = False self._waiting = False
else: else:
# POSIX # POSIX
if close_fds is _PLATFORM_DEFAULT_CLOSE_FDS:
# close_fds has different defaults on Py3/Py2
if PY3:
close_fds = True
else:
close_fds = False
if pass_fds and not close_fds: if pass_fds and not close_fds:
import warnings import warnings
warnings.warn("pass_fds overriding close_fds.", RuntimeWarning) warnings.warn("pass_fds overriding close_fds.", RuntimeWarning)
...@@ -768,7 +775,7 @@ class Popen(object): ...@@ -768,7 +775,7 @@ class Popen(object):
# Retain the process handle, but close the thread handle # Retain the process handle, but close the thread handle
self._handle = hp self._handle = hp
self.pid = pid self.pid = pid
ht.Close() _winapi.CloseHandle(ht) if not hasattr(ht, 'Close') else ht.Close()
def _internal_poll(self): def _internal_poll(self):
"""Check if child process has terminated. Returns returncode """Check if child process has terminated. Returns returncode
......
...@@ -38,7 +38,9 @@ NOT_IMPLEMENTED = { ...@@ -38,7 +38,9 @@ NOT_IMPLEMENTED = {
} }
COULD_BE_MISSING = { COULD_BE_MISSING = {
'socket': ['create_connection', 'RAND_add', 'RAND_egd', 'RAND_status']} 'socket': ['create_connection', 'RAND_add', 'RAND_egd', 'RAND_status'],
'subprocess': ['_posixsubprocess'],
}
NO_ALL = ['gevent.threading', 'gevent._util', NO_ALL = ['gevent.threading', 'gevent._util',
'gevent._socketcommon', 'gevent._socketcommon',
...@@ -83,7 +85,7 @@ class Test(unittest.TestCase): ...@@ -83,7 +85,7 @@ class Test(unittest.TestCase):
for name in self.__implements__ + self.__imports__: for name in self.__implements__ + self.__imports__:
if name in self.stdlib_all: if name in self.stdlib_all:
continue continue
if name in COULD_BE_MISSING.get(self.stdlib_name, []): if name in COULD_BE_MISSING.get(self.stdlib_name, ()):
continue continue
if name in dir(self.stdlib_module): # like thread._local which is not in thread.__all__ if name in dir(self.stdlib_module): # like thread._local which is not in thread.__all__
continue continue
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment