[pypy-commit] pypy default: clean up intermittently failing test_fork

bdkearns noreply at buildbot.pypy.org
Wed Jan 30 05:15:35 CET 2013


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r60702:3f31a9cbf0bf
Date: 2013-01-29 23:13 -0500
http://bitbucket.org/pypy/pypy/changeset/3f31a9cbf0bf/

Log:	clean up intermittently failing test_fork

diff --git a/pypy/module/thread/test/test_fork.py b/pypy/module/thread/test/test_fork.py
--- a/pypy/module/thread/test/test_fork.py
+++ b/pypy/module/thread/test/test_fork.py
@@ -1,7 +1,7 @@
 from pypy.module.thread.test.support import GenericTestThread
 
 class AppTestFork(GenericTestThread):
-    def test_fork(self):
+    def test_fork_with_thread(self):
         # XXX This test depends on a multicore machine, as busy_thread must
         # aquire the GIL the instant that the main thread releases it.
         # It will incorrectly pass if the GIL is not grabbed in time.
@@ -12,45 +12,48 @@
         if not hasattr(os, 'fork'):
             skip("No fork on this platform")
 
-        run = True
-        done = []
         def busy_thread():
             while run:
                 time.sleep(0)
             done.append(None)
 
-        try:
-            thread.start_new(busy_thread, ())
+        for i in range(1):
+            run = True
+            done = []
+            try:
+                thread.start_new(busy_thread, ())
+                print 'sleep'
 
-            pid = os.fork()
-
-            if pid == 0:
-                os._exit(0)
-
-            else:
-                time.sleep(1)
-                spid, status = os.waitpid(pid, os.WNOHANG)
-                assert spid == pid
-        finally:
-            run = False
-            self.waitfor(lambda: done)
+                pid = os.fork()
+                if pid == 0:
+                    os._exit(0)
+                else:
+                    self.timeout_killer(pid, 5)
+                    exitcode = os.waitpid(pid, 0)[1]
+                    assert exitcode == 0 # if 9, process was killed by timer!
+            finally:
+                run = False
+                self.waitfor(lambda: done)
+                assert done
 
     def test_forked_can_thread(self):
         "Checks that a forked interpreter can start a thread"
-        import os, thread, time
+        import thread
+        import os
 
         if not hasattr(os, 'fork'):
             skip("No fork on this platform")
 
-        # pre-allocate some locks
-        thread.start_new_thread(lambda: None, ())
+        for i in range(10):
+            # pre-allocate some locks
+            thread.start_new_thread(lambda: None, ())
+            print 'sleep'
 
-        pid = os.fork()
-        if pid == 0:
-            print 'in child'
-            thread.start_new_thread(lambda: None, ())
-            os._exit(0)
-        else:
-            self.timeout_killer(pid, 5)
-            exitcode = os.waitpid(pid, 0)[1]
-            assert exitcode == 0 # if 9, process was killed by timer!
+            pid = os.fork()
+            if pid == 0:
+                thread.start_new_thread(lambda: None, ())
+                os._exit(0)
+            else:
+                self.timeout_killer(pid, 5)
+                exitcode = os.waitpid(pid, 0)[1]
+                assert exitcode == 0 # if 9, process was killed by timer!


More information about the pypy-commit mailing list