]> granicus.if.org Git - python/commitdiff
Fixes issue #15507: test_subprocess's test_send_signal could fail if the test
authorGregory P. Smith <greg@krypto.org>
Thu, 29 Aug 2013 20:35:27 +0000 (13:35 -0700)
committerGregory P. Smith <greg@krypto.org>
Thu, 29 Aug 2013 20:35:27 +0000 (13:35 -0700)
runner were run in an environment where the process inherited an ignore
setting for SIGINT.  Restore the SIGINT handler to the desired
KeyboardInterrupt raising one during that test.

Lib/test/test_subprocess.py
Misc/NEWS

index f8cd1de325893456500a4daf433941041e445bf7..723845a13f30205cc9c35b6478e0f2a5771bce10 100644 (file)
@@ -1398,16 +1398,22 @@ class POSIXProcessTestCase(BaseTestCase):
     def _kill_process(self, method, *args):
         # Do not inherit file handles from the parent.
         # It should fix failures on some platforms.
-        p = subprocess.Popen([sys.executable, "-c", """if 1:
-                             import sys, time
-                             sys.stdout.write('x\\n')
-                             sys.stdout.flush()
-                             time.sleep(30)
-                             """],
-                             close_fds=True,
-                             stdin=subprocess.PIPE,
-                             stdout=subprocess.PIPE,
-                             stderr=subprocess.PIPE)
+        # Also set the SIGINT handler to the default to make sure it's not
+        # being ignored (some tests rely on that.)
+        old_handler = signal.signal(signal.SIGINT, signal.default_int_handler)
+        try:
+            p = subprocess.Popen([sys.executable, "-c", """if 1:
+                                 import sys, time
+                                 sys.stdout.write('x\\n')
+                                 sys.stdout.flush()
+                                 time.sleep(30)
+                                 """],
+                                 close_fds=True,
+                                 stdin=subprocess.PIPE,
+                                 stdout=subprocess.PIPE,
+                                 stderr=subprocess.PIPE)
+        finally:
+            signal.signal(signal.SIGINT, old_handler)
         # Wait for the interpreter to be completely initialized before
         # sending any signal.
         p.stdout.read(1)
index be2dc9dde816f04a96f5e65376ba9e55ecd34af5..4572ae6c379f960966c17643681e23424779401c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -309,6 +309,11 @@ IDLE
 Tests
 -----
 
+- Issue #15507: test_subprocess's test_send_signal could fail if the test
+  runner were run in an environment where the process inherited an ignore
+  setting for SIGINT.  Restore the SIGINT handler to the desired
+  KeyboardInterrupt raising one during that test.
+
 - Issue #18792: Use "127.0.0.1" or "::1" instead of "localhost" as much as
   possible, since "localhost" goes through a DNS lookup under recent Windows
   versions.