summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2010-12-13 06:45:02 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2010-12-13 06:45:02 (GMT)
commitf5604853889bfbbf84b48311c63c0e775dff38cc (patch)
tree658b18dc71ef66d0132e26b30821a2a385b4a639 /Lib
parent8d28a92eda3b5ab03552f6cf6b1cdce27445fb3e (diff)
downloadcpython-f5604853889bfbbf84b48311c63c0e775dff38cc.zip
cpython-f5604853889bfbbf84b48311c63c0e775dff38cc.tar.gz
cpython-f5604853889bfbbf84b48311c63c0e775dff38cc.tar.bz2
Get rid of the close_fds DeprecationWarning. Changes the default on a per
platform basis. It remains False on Windows and changes to True on all other platforms (POSIX). Based on python-dev discussion and http://bugs.python.org/issue7213.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/subprocess.py39
-rw-r--r--Lib/test/test_subprocess.py19
2 files changed, 20 insertions, 38 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 0b33157..62dfd36 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -27,7 +27,7 @@ This module defines one class called Popen:
class Popen(args, bufsize=0, executable=None,
stdin=None, stdout=None, stderr=None,
- preexec_fn=None, close_fds=False, shell=False,
+ preexec_fn=None, close_fds=_PLATFORM_DEFAULT, shell=False,
cwd=None, env=None, universal_newlines=False,
startupinfo=None, creationflags=0,
restore_signals=True, start_new_session=False):
@@ -39,12 +39,12 @@ args should be a string, or a sequence of program arguments. The
program to execute is normally the first item in the args sequence or
string, but can be explicitly set by using the executable argument.
-On UNIX, with shell=False (default): In this case, the Popen class
+On POSIX, with shell=False (default): In this case, the Popen class
uses os.execvp() to execute the child program. args should normally
be a sequence. A string will be treated as a sequence with the string
as the only item (the program to execute).
-On UNIX, with shell=True: If args is a string, it specifies the
+On POSIX, with shell=True: If args is a string, it specifies the
command string to execute through the shell. If args is a sequence,
the first item specifies the command string, and any additional items
will be treated as additional shell arguments.
@@ -73,14 +73,16 @@ parent. Additionally, stderr can be STDOUT, which indicates that the
stderr data from the applications should be captured into the same
file handle as for stdout.
-On UNIX, if preexec_fn is set to a callable object, this object will be
+On POSIX, if preexec_fn is set to a callable object, this object will be
called in the child process just before the child is executed. The use
of preexec_fn is not thread safe, using it in the presence of threads
could lead to a deadlock in the child process before the new executable
is executed.
If close_fds is true, all file descriptors except 0, 1 and 2 will be
-closed before the child process is executed.
+closed before the child process is executed. The default for close_fds
+varies by platform: False on Windows and True on all other platforms
+such as POSIX.
if shell is true, the specified command will be executed through the
shell.
@@ -88,12 +90,12 @@ shell.
If cwd is not None, the current directory will be changed to cwd
before the child is executed.
-On UNIX, if restore_signals is True all signals that Python sets to
+On POSIX, if restore_signals is True all signals that Python sets to
SIG_IGN are restored to SIG_DFL in the child process before the exec.
Currently this includes the SIGPIPE, SIGXFZ and SIGXFSZ signals. This
parameter does nothing on Windows.
-On UNIX, if start_new_session is True, the setsid() system call will be made
+On POSIX, if start_new_session is True, the setsid() system call will be made
in the child process prior to executing the command.
If env is not None, it defines the environment variables for the new
@@ -101,7 +103,7 @@ process.
If universal_newlines is true, the file objects stdout and stderr are
opened as a text files, but lines may be terminated by any of '\n',
-the Unix end-of-line convention, '\r', the Macintosh convention or
+the Unix end-of-line convention, '\r', the old Macintosh convention or
'\r\n', the Windows convention. All of these external representations
are seen as '\n' by the Python program. Note: This feature is only
available if Python is built with universal newline support (the
@@ -242,7 +244,7 @@ pid
returncode
The child return code. A None value indicates that the process
hasn't terminated yet. A negative value -N indicates that the
- child was terminated by signal N (UNIX only).
+ child was terminated by signal N (POSIX only).
Replacing older functions with the subprocess module
@@ -562,7 +564,7 @@ def list2cmdline(seq):
# Various tools for executing commands and looking at their output and status.
#
-# NB This only works (and is only relevant) for UNIX.
+# NB This only works (and is only relevant) for POSIX.
def getstatusoutput(cmd):
"""Return (status, output) of executing cmd in a shell.
@@ -602,10 +604,16 @@ def getoutput(cmd):
return getstatusoutput(cmd)[1]
+if mswindows:
+ _PLATFORM_DEFAULT = False
+else:
+ _PLATFORM_DEFAULT = True
+
+
class Popen(object):
def __init__(self, args, bufsize=0, executable=None,
stdin=None, stdout=None, stderr=None,
- preexec_fn=None, close_fds=None, shell=False,
+ preexec_fn=None, close_fds=_PLATFORM_DEFAULT, shell=False,
cwd=None, env=None, universal_newlines=False,
startupinfo=None, creationflags=0,
restore_signals=True, start_new_session=False,
@@ -619,15 +627,6 @@ class Popen(object):
if not isinstance(bufsize, int):
raise TypeError("bufsize must be an integer")
- if close_fds is None:
- # Notification for http://bugs.python.org/issue7213 & issue2320
- warnings.warn(
- 'The close_fds parameter was not specified. Its default'
- ' behavior will change in a future Python version. '
- ' Most users should set it to True. Please'
- ' update your code explicitly set close_fds.',
- DeprecationWarning)
-
if mswindows:
if preexec_fn is not None:
raise ValueError("preexec_fn is not supported on Windows "
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index f07f490..eaa26d2 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -58,22 +58,6 @@ class BaseTestCase(unittest.TestCase):
self.assertEqual(actual, expected, msg)
-class DeprecationWarningTests(BaseTestCase):
- def testCloseFdsWarning(self):
- quick_process = [sys.executable, "-c", "import sys; sys.exit(0)"]
- with warnings.catch_warnings(record=True) as warnlist:
- warnings.simplefilter("always")
- subprocess.call(quick_process, close_fds=True)
- self.assertEqual([], warnlist)
- subprocess.call(quick_process, close_fds=False)
- self.assertEqual([], warnlist)
- with self.assertWarns(DeprecationWarning) as wm:
- subprocess.Popen(quick_process).wait()
- self.assertEqual(1, len(wm.warnings))
- self.assertIn('close_fds parameter was not specified',
- str(wm.warnings[0]))
-
-
class ProcessTestCase(BaseTestCase):
def test_call_seq(self):
@@ -1250,8 +1234,7 @@ def test_main():
ProcessTestCaseNoPoll,
HelperFunctionTests,
CommandsWithSpaces,
- ContextManagerTests,
- DeprecationWarningTests)
+ ContextManagerTests)
support.run_unittest(*unit_tests)
support.reap_children()