]> granicus.if.org Git - python/commitdiff
Workaround #3137: Retry SIGINT if it is not received the first time.
authorFlorent Xicluna <florent.xicluna@gmail.com>
Fri, 5 Mar 2010 00:47:40 +0000 (00:47 +0000)
committerFlorent Xicluna <florent.xicluna@gmail.com>
Fri, 5 Mar 2010 00:47:40 +0000 (00:47 +0000)
test_send_signal should not hang anymore on various Linux distributions.

Lib/test/test_subprocess.py

index 1f3b09c538af79f8126c2be898bdcd4e9d087de8..ea4f5ab9f2fdcb4640b27d58a5760f920bc422cf 100644 (file)
@@ -654,9 +654,20 @@ class POSIXProcessTestCase(unittest.TestCase):
         p = subprocess.Popen([sys.executable, "-c", "input()"])
 
         # Let the process initialize correctly (Issue #3137)
-        time.sleep(.1)
+        time.sleep(0.1)
         self.assertIs(p.poll(), None)
-        p.send_signal(signal.SIGINT)
+        count, maxcount = 0, 3
+        # Retry if the process do not receive the SIGINT signal.
+        while count < maxcount and p.poll() is None:
+            p.send_signal(signal.SIGINT)
+            time.sleep(0.1)
+            count += 1
+        if p.poll() is None:
+            raise test_support.TestFailed("the subprocess did not receive "
+                                          "the signal SIGINT")
+        elif count > 1:
+            print >>sys.stderr, ("p.send_signal(SIGINT) succeeded "
+                                 "after {} attempts".format(count))
         self.assertNotEqual(p.wait(), 0)
 
     def test_kill(self):