cpython: f452d7d5470d (original) (raw)

Mercurial > cpython

changeset 75525:f452d7d5470d

Issue #14252: Fix subprocess.Popen.terminate() to not raise an error under Windows when the child process has already exited. [#14252]

Antoine Pitrou solipsis@pitrou.net
date Sun, 11 Mar 2012 19:33:29 +0100
parents 8ecd1a1c7dfc(current diff)41b1fe5a75a6(diff)
children 2b7c39db2150 4b54a686541f fd60aab46733
files Lib/subprocess.py Lib/test/test_subprocess.py Misc/NEWS PC/_subprocess.c
diffstat 4 files changed, 80 insertions(+), 1 deletions(-)[+] [-] Lib/subprocess.py 10 Lib/test/test_subprocess.py 67 Misc/NEWS 3 PC/_subprocess.c 1

line wrap: on

line diff

--- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1162,7 +1162,15 @@ class Popen(object): def terminate(self): """Terminates the process """

kill = terminate

--- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -1078,6 +1078,27 @@ class POSIXProcessTestCase(BaseTestCase) getattr(p, method)(*args) return p

+ def test_send_signal(self): p = self._kill_process('send_signal', signal.SIGINT) _, stderr = p.communicate() @@ -1096,6 +1117,18 @@ class POSIXProcessTestCase(BaseTestCase) self.assertStderrEqual(stderr, b'') self.assertEqual(p.wait(), -signal.SIGTERM)

+

+

+ def check_close_std_fds(self, fds): # Issue #9905: test that subprocess pipes still work properly with # some standard fds closed @@ -1662,6 +1695,31 @@ class Win32ProcessTestCase(BaseTestCase) returncode = p.wait() self.assertNotEqual(returncode, 0)

+ def test_send_signal(self): self._kill_process('send_signal', signal.SIGTERM) @@ -1671,6 +1729,15 @@ class Win32ProcessTestCase(BaseTestCase) def test_terminate(self): self._kill_process('terminate')

+

+

+

The module says:

"NB This only works (and is only relevant) for UNIX."

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -22,6 +22,9 @@ Core and Builtins Library ------- +- Issue #14252: Fix subprocess.Popen.terminate() to not raise an error under

--- a/PC/_subprocess.c +++ b/PC/_subprocess.c @@ -691,6 +691,7 @@ PyInit__subprocess() defint(d, "WAIT_TIMEOUT", WAIT_TIMEOUT); defint(d, "CREATE_NEW_CONSOLE", CREATE_NEW_CONSOLE); defint(d, "CREATE_NEW_PROCESS_GROUP", CREATE_NEW_PROCESS_GROUP);

return m; }