From: Antoine Pitrou Date: Sun, 11 Mar 2012 18:33:29 +0000 (+0100) Subject: Issue #14252: Fix subprocess.Popen.terminate() to not raise an error under Windows... X-Git-Tag: v3.3.0a2~238 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b69ef16fe63e6de91c5d659bd83d9eff67b38d98;p=python Issue #14252: Fix subprocess.Popen.terminate() to not raise an error under Windows when the child process has already exited. --- b69ef16fe63e6de91c5d659bd83d9eff67b38d98 diff --cc Lib/subprocess.py index a0aadb91a2,179f41a85f..684086bb5c --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@@ -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 diff --cc Misc/NEWS index 29e8899421,5d03fee8e7..7055bd3e29 --- a/Misc/NEWS +++ b/Misc/NEWS @@@ -22,23 -22,32 +22,26 @@@ Core and Builtin Library ------- + - Issue #14252: Fix subprocess.Popen.terminate() to not raise an error under + Windows when the child process has already exited. + -- 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 #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 ----------------- diff --cc PC/_subprocess.c index 93e51d3539,f9a79a7300..13a5e1f194 --- a/PC/_subprocess.c +++ b/PC/_subprocess.c @@@ -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; }