def dumpAllThreads(): import sys if not hasattr(sys, "_current_frames"): print "Warning: dumpAllThreads: no sys._current_frames" return import threading id2name = dict([(th.ident, th.name) for th in threading.enumerate()]) for threadId, stack in sys._current_frames().items(): print("\n# Thread: %s(%d)" % (id2name.get(threadId,""), threadId)) better_exchook.print_traceback(stack)
def dumpAllThreads(): import sys if not hasattr(sys, "_current_frames"): print "Warning: dumpAllThreads: no sys._current_frames" return import threading id2name = dict([(th.ident, th.name) for th in threading.enumerate()]) for threadId, stack in sys._current_frames().items(): print("\n# Thread: %s(%d)" % (id2name.get(threadId, ""), threadId)) better_exchook.print_traceback(stack)
def dumpThread(threadId): import sys if not hasattr(sys, "_current_frames"): print "Warning: dumpThread: no sys._current_frames" return if threadId not in sys._current_frames(): print("Thread %d not found" % threadId) return stack = sys._current_frames()[threadId] better_exchook.print_traceback(stack)
def debugWarn(msg): print "Warning:", msg import sys if not hasattr(sys, "_getframe"): print "Warning: debugWarn: no sys._getframe" return f = sys._getframe() if not f: print "Warning: debugWarn: no frame" f = f.f_back if not f: print "Warning: debugWarn: no previous frame" better_exchook.print_traceback(f)
def excepthook(exc_type, exc_obj, exc_tb): print "Unhandled exception %s in thread %s, proc %s." % (exc_type, threading.currentThread(), os.getpid()) better_exchook.better_exchook(exc_type, exc_obj, exc_tb) if main_thread_id == thread.get_ident(): print "We are the main thread." if not isinstance(exc_type, Exception): # We are the main thread and we got an exit-exception. This is likely fatal. # This usually means an exit. (We ignore non-daemon threads and procs here.) # Print the stack of all other threads. if hasattr(sys, "_current_frames"): print "" threads = {t.ident: t for t in threading.enumerate()} for tid, stack in sys._current_frames().items(): if tid != main_thread_id: print "Thread %s:" % threads.get(tid, "unnamed with id %i" % tid) better_exchook.print_traceback(stack) print ""