Issue #14252: Fix subprocess.Popen.terminate() to not raise an error under Windows...
authorAntoine Pitrou <solipsis@pitrou.net>
Sun, 11 Mar 2012 18:33:29 +0000 (19:33 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Sun, 11 Mar 2012 18:33:29 +0000 (19:33 +0100)
1  2 
Lib/subprocess.py
Lib/test/test_subprocess.py
Misc/NEWS
PC/_subprocess.c

index a0aadb91a23b8fd780aa8a8ae933a1d713da6bf5,179f41a85f56c82def6489d77e07f0dede23c66c..684086bb5c0173dfbecd1f7c679c3341b00e50be
@@@ -1162,7 -1075,17 +1162,15 @@@ class Popen(object)
          def terminate(self):
              """Terminates the process
              """
-             _subprocess.TerminateProcess(self._handle, 1)
+             try:
+                 _subprocess.TerminateProcess(self._handle, 1)
 -            except OSError as e:
++            except PermissionError:
+                 # ERROR_ACCESS_DENIED (winerror 5) is received when the
+                 # process already died.
 -                if e.winerror != 5:
 -                    raise
+                 rc = _subprocess.GetExitCodeProcess(self._handle)
+                 if rc == _subprocess.STILL_ACTIVE:
+                     raise
+                 self.returncode = rc
  
          kill = terminate
  
Simple merge
diff --cc Misc/NEWS
index 29e88994211efdec68cda337da80a94bd00c8d81,5d03fee8e74c83bdb7b1159d548481bd43f81b7b..7055bd3e29e0bdf2913baee11ef5300902ab0ef6
+++ b/Misc/NEWS
@@@ -22,23 -22,32 +22,26 @@@ Core and Builtin
  Library
  -------
  
 -- Issue #14195: An issue that caused weakref.WeakSet instances to incorrectly
 -  return True for a WeakSet instance 'a' in both 'a < a' and 'a > a' has been
 -  fixed.
 -
 -- Issue #14177: marshal.loads() now raises TypeError when given an unicode
 -  string.  Patch by Guilherme Gonçalves.
 -
 -- Issue #14159: Fix the len() of weak containers (WeakSet, WeakKeyDictionary,
 -  WeakValueDictionary) to return a better approximation when some objects
 -  are dead or dying.  Moreover, the implementation is now O(1) rather than
 -  O(n).
+ - Issue #14252: Fix subprocess.Popen.terminate() to not raise an error under
+   Windows when the child process has already exited.
 +- Issue #14223: curses.addch() is no more limited to the range 0-255 when the
 +  Python curses is not linked to libncursesw. It was a regression introduced
 +  in Python 3.3a1.
  
 -- Issue #13125: Silence spurious test_lib2to3 output when in non-verbose mode.
 -  Patch by Mikhail Novikov.
 +- Issue #14168: Check for presence of Element._attrs in minidom before
 +  accessing it.
  
 -- Issue #13447: Add a test file to host regression tests for bugs in the
 -  scripts found in the Tools directory.
 +- Issue #12328: Fix multiprocessing's use of overlapped I/O on Windows.
 +  Also, add a multiprocessing.connection.wait(rlist, timeout=None) function
 +  for polling multiple objects at once.  Patch by sbt.
  
 -- Issue #6884: Fix long-standing bugs with MANIFEST.in parsing in distutils
 -  on Windows.
 +- Issue #14007: Accept incomplete TreeBuilder objects (missing start, end,
 +  data or close method) for the Python implementation as well.
 +  Drop the no-op TreeBuilder().xml() method from the C implementation.
  
 -- Issue #8033: sqlite3: Fix 64-bit integer handling in user functions
 -  on 32-bit architectures. Initial patch by Philippe Devalkeneer.
 +- Issue #14210: pdb now has tab-completion not only for command names, but
 +  also for their arguments, wherever possible.
  
  Extension Modules
  -----------------
index 93e51d353990f2541fcd83ac1037986d92494642,f9a79a73007aa3990395762c748f77bdfbd3659f..13a5e1f19447caf2e9ce1176d41db940d310e7d8
@@@ -688,9 -682,9 +688,10 @@@ PyInit__subprocess(
      defint(d, "SW_HIDE", SW_HIDE);
      defint(d, "INFINITE", INFINITE);
      defint(d, "WAIT_OBJECT_0", WAIT_OBJECT_0);
 +    defint(d, "WAIT_TIMEOUT", WAIT_TIMEOUT);
      defint(d, "CREATE_NEW_CONSOLE", CREATE_NEW_CONSOLE);
      defint(d, "CREATE_NEW_PROCESS_GROUP", CREATE_NEW_PROCESS_GROUP);
+     defint(d, "STILL_ACTIVE", STILL_ACTIVE);
  
      return m;
  }