]> granicus.if.org Git - python/commitdiff
Add new utility function, reap_children(), to test_support. This should
authorNeal Norwitz <nnorwitz@gmail.com>
Thu, 29 Jun 2006 04:10:08 +0000 (04:10 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Thu, 29 Jun 2006 04:10:08 +0000 (04:10 +0000)
be called at the end of each test that spawns children (perhaps it
should be called from regrtest instead?).  This will hopefully prevent
some of the unexplained failures in the buildbots (hppa and alpha)
during tests that spawn children.  The problems were not reproducible.
There were many zombies that remained at the end of several tests.
In the worst case, this shouldn't cause any more problems,
though it may not help either.  Time will tell.

14 files changed:
Lib/test/test_bz2.py
Lib/test/test_cmd_line.py
Lib/test/test_commands.py
Lib/test/test_fork1.py
Lib/test/test_mailbox.py
Lib/test/test_popen.py
Lib/test/test_popen2.py
Lib/test/test_select.py
Lib/test/test_socketserver.py
Lib/test/test_subprocess.py
Lib/test/test_support.py
Lib/test/test_wait3.py
Lib/test/test_wait4.py
Misc/NEWS

index 504a6d771ed46f2f71e7651566760dcc0e02a977..79acc07899b78bf5fb8b1b765e87186259b3368b 100644 (file)
@@ -352,6 +352,7 @@ def test_main():
         BZ2DecompressorTest,
         FuncTest
     )
+    test_support.reap_children()
 
 if __name__ == '__main__':
     test_main()
index ec860d1ef05bfa182818b7afddb48fd9b7227e02..5e898634d96044d92073107eac259fb9451f4bf2 100644 (file)
@@ -87,6 +87,7 @@ class CmdLineTest(unittest.TestCase):
 
 def test_main():
     test.test_support.run_unittest(CmdLineTest)
+    test.test_support.reap_children()
 
 if __name__ == "__main__":
     test_main()
index 0f7d15f1849813848e1aa4f2abcd0065fa9bf4c6..b72a1b9b6acb74ae0b6f2fb4bb7ab5fd3484965c 100644 (file)
@@ -5,7 +5,7 @@
 import unittest
 import os, tempfile, re
 
-from test.test_support import TestSkipped, run_unittest
+from test.test_support import TestSkipped, run_unittest, reap_children
 from commands import *
 
 # The module says:
@@ -58,6 +58,7 @@ class CommandTests(unittest.TestCase):
 
 def test_main():
     run_unittest(CommandTests)
+    reap_children()
 
 
 if __name__ == "__main__":
index cba5fc7d19e76cc8dcd0a0e89094408a01c107ee..e909844e912b89cd1979c5faaead08a1e4091929 100644 (file)
@@ -3,7 +3,7 @@
 
 import os
 from test.fork_wait import ForkWait
-from test.test_support import TestSkipped, run_unittest
+from test.test_support import TestSkipped, run_unittest, reap_children
 
 try:
     os.fork
@@ -18,6 +18,7 @@ class ForkTest(ForkWait):
 
 def test_main():
     run_unittest(ForkTest)
+    reap_children()
 
 if __name__ == "__main__":
     test_main()
index 474354f545d97d0a852015e0871f25a4cf2ef2e2..2f8cb8d55f0fd06bb64e85f55e9c1abdf24e05cf 100644 (file)
@@ -1785,6 +1785,7 @@ def test_main():
              TestMessageConversion, TestProxyFile, TestPartialFile,
              MaildirTestCase)
     test_support.run_unittest(*tests)
+    test_support.reap_children()
 
 
 if __name__ == '__main__':
index 2b687ad31ecbec76efa0fc5496dde1cdb35c7538..fbf5e054eb68e9cede841eb61e662dc60d3db492 100644 (file)
@@ -6,7 +6,7 @@
 
 import os
 import sys
-from test.test_support import TestSkipped
+from test.test_support import TestSkipped, reap_children
 from os import popen
 
 # Test that command-lines get down as we expect.
@@ -35,5 +35,6 @@ def _test_commandline():
 def main():
     print "Test popen:"
     _test_commandline()
+    reap_children()
 
 main()
index 4db3cd1f5524a7975c3d266c5430eadbbd470850..2d54eb008d00d7c8e8653aa891b8c353f473500c 100644 (file)
@@ -5,7 +5,7 @@
 
 import os
 import sys
-from test.test_support import TestSkipped
+from test.test_support import TestSkipped, reap_children
 
 # popen2 contains its own testing routine
 # which is especially useful to see if open files
@@ -75,3 +75,4 @@ def _test():
 
 main()
 _test()
+reap_children()
index eaec52be194b7c20b7ce7aaaa35afc63273b6fb3..d341324094be15b0951ed1dbc45a46d17b3f5e65 100644 (file)
@@ -1,5 +1,5 @@
 # Testing select module
-from test.test_support import verbose
+from test.test_support import verbose, reap_children
 import select
 import os
 
@@ -65,5 +65,6 @@ def test():
             continue
         print 'Unexpected return values from select():', rfd, wfd, xfd
     p.close()
+    reap_children()
 
 test()
index 93165470f922adc594064c3b5688594047cea0f7..dd4532fa4ea5fcd8fa1c604034ef9b990ab10303 100644 (file)
@@ -1,7 +1,8 @@
 # Test suite for SocketServer.py
 
 from test import test_support
-from test.test_support import verbose, verify, TESTFN, TestSkipped
+from test.test_support import (verbose, verify, TESTFN, TestSkipped,
+                               reap_children)
 test_support.requires('network')
 
 from SocketServer import *
@@ -199,6 +200,7 @@ def test_main():
         testall()
     finally:
         cleanup()
+    reap_children()
 
 if __name__ == "__main__":
     test_main()
index 9877f51783c6e36e38b963972f3af66ec9f79042..b4e6c00d2ee47e0f55480fb0cd3db0cdf49515d1 100644 (file)
@@ -27,6 +27,16 @@ def remove_stderr_debug_decorations(stderr):
     return re.sub(r"\[\d+ refs\]\r?\n?$", "", stderr)
 
 class ProcessTestCase(unittest.TestCase):
+    def setUp(self):
+       # Try to minimize the number of children we have so this test
+       # doesn't crash on some buildbots (Alphas in particular).
+        test_support.reap_children()
+
+    def tearDown(self):
+       # Try to minimize the number of children we have so this test
+       # doesn't crash on some buildbots (Alphas in particular).
+        test_support.reap_children()
+
     def mkstemp(self):
         """wrapper for mkstemp, calling mktemp if mkstemp is not available"""
         if hasattr(tempfile, "mkstemp"):
@@ -600,6 +610,7 @@ class ProcessTestCase(unittest.TestCase):
 
 def test_main():
     test_support.run_unittest(ProcessTestCase)
+    test_support.reap_children()
 
 if __name__ == "__main__":
     test_main()
index 8e315496ee1292f5e4a02cfadd74c193a9619e4c..6532c79a997f3718c6b97230d85e1842bf295949 100644 (file)
@@ -475,3 +475,24 @@ def threading_cleanup(num_active, num_limbo):
     while len(threading._limbo) != num_limbo and count < _MAX_COUNT:
         count += 1
         time.sleep(0.1)
+
+def reap_children():
+    """Use this function at the end of test_main() whenever sub-processes
+    are started.  This will help ensure that no extra children (zombies)
+    stick around to hog resources and create problems when looking
+    for refleaks.
+    """
+
+    # Reap all our dead child processes so we don't leave zombies around.
+    # These hog resources and might be causing some of the buildbots to die.
+    import os
+    if hasattr(os, 'waitpid'):
+        any_process = -1
+        while True:
+            try:
+                # This will raise an exception on Windows.  That's ok.
+                pid, status = os.waitpid(any_process, os.WNOHANG)
+                if pid == 0:
+                    break
+            except:
+                break
index f6a41a698cb0d5a90cc241b046a4e7890554eba2..82799732fe5e040692161a9555040f912e103cf8 100644 (file)
@@ -3,7 +3,7 @@
 
 import os
 from test.fork_wait import ForkWait
-from test.test_support import TestSkipped, run_unittest
+from test.test_support import TestSkipped, run_unittest, reap_children
 
 try:
     os.fork
@@ -27,6 +27,7 @@ class Wait3Test(ForkWait):
 
 def test_main():
     run_unittest(Wait3Test)
+    reap_children()
 
 if __name__ == "__main__":
     test_main()
index 027e5c35249c89ceceb52d48aa70f76843cb3a35..711fd2dc3895904dcc07a13d03a998a5f54b7d7f 100644 (file)
@@ -3,7 +3,7 @@
 
 import os
 from test.fork_wait import ForkWait
-from test.test_support import TestSkipped, run_unittest
+from test.test_support import TestSkipped, run_unittest, reap_children
 
 try:
     os.fork
@@ -24,6 +24,7 @@ class Wait4Test(ForkWait):
 
 def test_main():
     run_unittest(Wait4Test)
+    reap_children()
 
 if __name__ == "__main__":
     test_main()
index 9612812db88f31ee42e170e7734e7ee198e6e8a2..8e83867b3c2478b29a5743bb60924ed4edf4875f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -48,6 +48,12 @@ Build
 - Bug #1513032: 'make install' failed on FreeBSD 5.3 due to lib-old
   trying to be installed even though it's empty.
 
+Tests
+-----
+
+- Call os.waitpid() at the end of tests that spawn child processes in order
+  to minimize resources (zombies).
+
 
 What's New in Python 2.5 beta 1?
 ================================