[Python-checkins] cpython (3.6): Issue #20572: The subprocess.Popen.wait method's undocumented endtime

gregory.p.smith python-checkins at python.org
Sun Nov 20 19:31:16 EST 2016


https://hg.python.org/cpython/rev/0e8aa537c565
changeset:   105250:0e8aa537c565
branch:      3.6
parent:      105243:8372b9a325fb
user:        Gregory P. Smith <greg at krypto.org>
date:        Sun Nov 20 16:25:14 2016 -0800
summary:
  Issue #20572: The subprocess.Popen.wait method's undocumented endtime
parameter now raises a DeprecationWarning.  It was deprecated in 3.4.
It was never documented prior to that.

files:
  Lib/subprocess.py           |  11 ++++++++-
  Lib/test/test_subprocess.py |  27 ++++++++++++------------
  Misc/NEWS                   |   3 ++
  3 files changed, 25 insertions(+), 16 deletions(-)


diff --git a/Lib/subprocess.py b/Lib/subprocess.py
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -1031,6 +1031,10 @@
             """Wait for child process to terminate.  Returns returncode
             attribute."""
             if endtime is not None:
+                warnings.warn(
+                    "'endtime' argument is deprecated; use 'timeout'.",
+                    DeprecationWarning,
+                    stacklevel=2)
                 timeout = self._remaining_time(endtime)
             if timeout is None:
                 timeout_millis = _winapi.INFINITE
@@ -1392,8 +1396,11 @@
             if self.returncode is not None:
                 return self.returncode
 
-            # endtime is preferred to timeout.  timeout is only used for
-            # printing.
+            if endtime is not None:
+                warnings.warn(
+                    "'endtime' argument is deprecated; use 'timeout'.",
+                    DeprecationWarning,
+                    stacklevel=2)
             if endtime is not None or timeout is not None:
                 if endtime is None:
                     endtime = _time() + timeout
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -1015,6 +1015,19 @@
         # time to start.
         self.assertEqual(p.wait(timeout=3), 0)
 
+    def test_wait_endtime(self):
+        """Confirm that the deprecated endtime parameter warns."""
+        p = subprocess.Popen([sys.executable, "-c", "pass"])
+        try:
+            with self.assertWarns(DeprecationWarning) as warn_cm:
+                p.wait(endtime=time.time()+0.01)
+        except subprocess.TimeoutExpired:
+            pass  # We're not testing endtime timeout behavior.
+        finally:
+            p.kill()
+        self.assertIn('test_subprocess.py', warn_cm.filename)
+        self.assertIn('endtime', str(warn_cm.warning))
+
     def test_invalid_bufsize(self):
         # an invalid type of the bufsize argument should raise
         # TypeError.
@@ -2777,19 +2790,5 @@
         self.assertTrue(proc.stdin.closed)
 
 
-def test_main():
-    unit_tests = (ProcessTestCase,
-                  POSIXProcessTestCase,
-                  Win32ProcessTestCase,
-                  MiscTests,
-                  ProcessTestCaseNoPoll,
-                  CommandsWithSpaces,
-                  ContextManagerTests,
-                  RunFuncTestCase,
-                  )
-
-    support.run_unittest(*unit_tests)
-    support.reap_children()
-
 if __name__ == "__main__":
     unittest.main()
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -40,6 +40,9 @@
 Library
 -------
 
+- Issue #20572: The subprocess.Popen.wait method's undocumented
+  endtime parameter now raises a DeprecationWarning.
+
 - Issue #25659: In ctypes, prevent a crash calling the from_buffer() and
   from_buffer_copy() methods on abstract classes like Array.
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list