Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar/TracebackUtils.py
diff options
context:
space:
mode:
authorDan Williams <dcbw@localhost.localdomain>2006-08-17 03:05:44 (GMT)
committer Dan Williams <dcbw@localhost.localdomain>2006-08-17 03:05:44 (GMT)
commit95c06280ca214fe13570e5aebd0d40857f90610c (patch)
treeb314f9585e6aeb0037fe767af45289205043e800 /sugar/TracebackUtils.py
parent653065363639ebb59bcbbd682c6a0249dd475f11 (diff)
Add threadframe and TracebackUtils.py so we can get tracebacks of dbus deadlocks
Diffstat (limited to 'sugar/TracebackUtils.py')
-rw-r--r--sugar/TracebackUtils.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/sugar/TracebackUtils.py b/sugar/TracebackUtils.py
new file mode 100644
index 0000000..3973da1
--- /dev/null
+++ b/sugar/TracebackUtils.py
@@ -0,0 +1,37 @@
+import sys
+import traceback
+import os
+import signal
+
+haveThreadframe = True
+try:
+ import threadframe
+except ImportError:
+ haveThreadframe = False
+
+class TracebackHelper(object):
+ def __init__(self):
+ fname = "%s-%d" % (os.path.basename(sys.argv[0]), os.getpid())
+ self._fpath = os.path.join("/tmp", fname)
+ print "Tracebacks will be written to %s on SIGUSR1" % self._fpath
+ signal.signal(signal.SIGUSR1, self._handler)
+
+ def __del__(self):
+ try:
+ os.remove(self._fpath)
+ except OSError:
+ pass
+
+ def _handler(self, signum, pframe):
+ f = open(self._fpath, "a")
+ if not haveThreadframe:
+ f.write("Threadframe not installed. No traceback available.\n")
+ else:
+ frames = threadframe.dict()
+ for thread_id, frame in frames.iteritems():
+ f.write(('-' * 79) + '\n')
+ f.write('[Thread %s] %d' % (thread_id, sys.getrefcount(frame)) + '\n')
+ traceback.print_stack(frame, limit=None, file=f)
+ f.write("\n")
+ f.write('\n')
+ f.close()