[PATCH] add some thread logging

Brian C. Lane bcl at redhat.com
Mon Oct 8 23:37:34 UTC 2012


From: "Brian C. Lane" <bcl at redhat.com>

 * log when threads are started and are finished
 * log progress messages
 * log all the running threads and their stack frame when USR2 is
   received.
---
 pyanaconda/__init__.py | 9 +++++++++
 pyanaconda/progress.py | 4 ++++
 pyanaconda/threads.py  | 5 +++++
 3 files changed, 18 insertions(+)

diff --git a/pyanaconda/__init__.py b/pyanaconda/__init__.py
index 5154e44..c46d20c 100644
--- a/pyanaconda/__init__.py
+++ b/pyanaconda/__init__.py
@@ -29,6 +29,7 @@
 #
 
 import os, time, string
+import sys
 import iutil
 import isys
 from constants import ROOT_PATH
@@ -179,15 +180,23 @@ class Anaconda(object):
     def dumpState(self):
         from meh.dump import ReverseExceptionDump
         from inspect import stack as _stack
+        from traceback import format_stack
 
         # Skip the frames for dumpState and the signal handler.
         stack = _stack()[2:]
         stack.reverse()
         exn = ReverseExceptionDump((None, None, stack), self.mehConfig)
 
+        # gather up info on the running threads
+        threads = "\nThreads\n-------\n"
+        for thread_id, frame in sys._current_frames().iteritems():
+            threads += "\nThread %s\n" % (thread_id,)
+            threads += "".join(format_stack(frame))
+
         # dump to a unique file
         (fd, filename) = mkstemp(prefix="anaconda-tb-", dir="/tmp")
         dump_text = exn.traceback_and_object_dump(self)
+        dump_text += threads
         dump_text = dump_text.encode("utf-8")
         os.write(fd, dump_text)
         os.close(fd)
diff --git a/pyanaconda/progress.py b/pyanaconda/progress.py
index a671fad..433d205 100644
--- a/pyanaconda/progress.py
+++ b/pyanaconda/progress.py
@@ -18,6 +18,9 @@
 #
 # Author(s): Chris Lumens <clumens at redhat.com>
 
+import logging
+log = logging.getLogger("anaconda")
+
 from contextlib import contextmanager
 import Queue
 
@@ -66,5 +69,6 @@ def send_quit(code):
 @contextmanager
 def progress_report(message):
     send_message(message)
+    log.info(message)
     yield
     send_step()
diff --git a/pyanaconda/threads.py b/pyanaconda/threads.py
index 2119a7f..55fe141 100644
--- a/pyanaconda/threads.py
+++ b/pyanaconda/threads.py
@@ -19,6 +19,9 @@
 #
 # Author(s):  Chris Lumens <clumens at redhat.com>
 #
+import logging
+log = logging.getLogger("anaconda")
+
 import threading
 
 class ThreadManager(object):
@@ -83,6 +86,7 @@ class AnacondaThread(threading.Thread):
         # http://bugs.python.org/issue1230540#msg25696
         import sys
 
+        log.info("Running Thread: %s (%s)" % (self.name, self.ident))
         try:
             threading.Thread.run(self, *args, **kwargs)
         except KeyboardInterrupt:
@@ -91,6 +95,7 @@ class AnacondaThread(threading.Thread):
             sys.excepthook(*sys.exc_info())
         finally:
             threadMgr.remove(self.name)
+            log.info("Thread Done: %s (%s)" % (self.name, self.ident))
 
 def initThreading():
     """Set up threading for anaconda's use.  This method must be called before
-- 
1.7.11.4



More information about the anaconda-patches mailing list