Author: Alex Gaynor <alex.gay...@gmail.com>
Branch: 
Changeset: r60704:fe4735de4d71
Date: 2013-01-29 20:25 -0800
http://bitbucket.org/pypy/pypy/changeset/fe4735de4d71/

Log:    merged upstream

diff --git a/pypy/module/thread/test/support.py 
b/pypy/module/thread/test/support.py
--- a/pypy/module/thread/test/support.py
+++ b/pypy/module/thread/test/support.py
@@ -2,6 +2,7 @@
 import time
 import thread
 import os
+import errno
 
 from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.module.thread import gil
@@ -28,7 +29,12 @@
     def kill():
         for x in range(delay * 10):
             time.sleep(0.1)
-            os.kill(pid, 0)
+            try:
+                os.kill(pid, 0)
+            except OSError, e:
+                if e.errno == errno.ESRCH: # no such process
+                    return
+                raise
         os.kill(pid, 9)
         print "process %s killed!" % (pid,)
     thread.start_new_thread(kill, ())
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!
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to