[Piglit] [PATCH] framework: avoid blocking joins, allowing ^C to work

Ilia Mirkin imirkin at alum.mit.edu
Sat Feb 15 00:27:44 PST 2014


Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
---
 framework/core.py | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/framework/core.py b/framework/core.py
index 4bcaa82..7b2083b 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -31,6 +31,7 @@ import sys
 import time
 import traceback
 from cStringIO import StringIO
+import itertools
 import multiprocessing
 import multiprocessing.dummy
 import importlib
@@ -578,22 +579,29 @@ class TestProfile(object):
         chunksize = 1
 
         if env.concurrent == "all":
-            multi.imap(test, self.test_list.iteritems(), chunksize)
+            testiter = multi.imap(test, self.test_list.iteritems(), chunksize)
         elif env.concurrent == "none":
-            single.imap(test, self.test_list.iteritems(), chunksize)
+            testiter = single.imap(test, self.test_list.iteritems(), chunksize)
         else:
             # Filter and return only thread safe tests to the threaded pool
-            multi.imap(test, (x for x in self.test_list.iteritems() if
-                              x[1].runConcurrent), chunksize)
+            iter1 = multi.imap(test, (x for x in self.test_list.iteritems()
+                                      if x[1].runConcurrent), chunksize)
             # Filter and return the non thread safe tests to the single pool
-            single.imap(test, (x for x in self.test_list.iteritems() if not
-                               x[1].runConcurrent), chunksize)
+            iter2 = single.imap(test, (x for x in self.test_list.iteritems()
+                                       if not x[1].runConcurrent), chunksize)
+            testiter = itertools.chain(iter1, iter2)
 
         # Close and join the pools
         # If we don't close and the join the pools the script will exit before
         # the pools finish running
         multi.close()
         single.close()
+
+        # This waits for all the results to arrive in a non-blocking
+        # fashion. This in turn allows ^C to work to stop a piglit run.
+        for test in testiter:
+            pass
+
         multi.join()
         single.join()
 
-- 
1.8.3.2



More information about the Piglit mailing list