Error if threads leak.

Leaky threads lead to tests failing because they starve CPU time
particularly when run on machines with fewer CPUs (so the threads can
concentrate their leakyness on a single python process). Avoid these
problems in the future by erroring if any leak.

Change-Id: I73cb815fc079af879e04a95d908097a4275cf4b3
diff --git a/tests/base.py b/tests/base.py
index 7a39e20..5f6022a 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -38,6 +38,7 @@
 import sys
 import tempfile
 import threading
+import traceback
 import time
 import uuid
 
@@ -1654,13 +1655,18 @@
         self.gearman_server.shutdown()
         self.fake_nodepool.stop()
         self.zk.disconnect()
+        self.printHistory()
         # we whitelist watchdog threads as they have relatively long delays
         # before noticing they should exit, but they should exit on their own.
         threads = [t for t in threading.enumerate()
                    if t.name != 'executor-watchdog']
         if len(threads) > 1:
-            self.log.error("More than one thread is running: %s" % threads)
-        self.printHistory()
+            log_str = ""
+            for thread_id, stack_frame in sys._current_frames().items():
+                log_str += "Thread: %s\n" % thread_id
+                log_str += "".join(traceback.format_stack(stack_frame))
+            self.log.debug(log_str)
+            raise Exception("More than one thread is running: %s" % threads)
 
     def assertCleanShutdown(self):
         pass