[pypy-commit] pypy default: Waiting 0.5 seconds is by far not enough on Windows. Sleep until all

arigo noreply at buildbot.pypy.org
Sun Sep 7 09:30:36 CEST 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r73358:d5571baf1ff6
Date: 2014-09-07 09:30 +0200
http://bitbucket.org/pypy/pypy/changeset/d5571baf1ff6/

Log:	Waiting 0.5 seconds is by far not enough on Windows. Sleep until
	all threads are finished.

diff --git a/pypy/module/thread/test/test_thread.py b/pypy/module/thread/test/test_thread.py
--- a/pypy/module/thread/test/test_thread.py
+++ b/pypy/module/thread/test/test_thread.py
@@ -13,18 +13,26 @@
         def f():
             lock.acquire()
             lock.release()
+        start = thread._count()
         try:
             try:
                 for i in range(1000):
                     thread.start_new_thread(f, ())
             finally:
                 lock.release()
-                # wait a bit to allow most threads to finish now
-                time.sleep(0.5)
         except (thread.error, MemoryError):
             cls.w_can_start_many_threads = space.wrap(False)
         else:
             cls.w_can_start_many_threads = space.wrap(True)
+        # wait a bit to allow all threads to finish now
+        remaining = thread._count()
+        retries = 0
+        while remaining > start:
+            retries += 1
+            if retries == 200:
+                raise Exception("the test's threads don't stop!")
+            time.sleep(0.2)
+            remaining = thread._count()
 
     def test_start_new_thread(self):
         import thread


More information about the pypy-commit mailing list