def _dump_threads(stream): """Built in in Python 2.5, needed for earlier versions""" for i,frame in enumerate(threadframe.threadframe()): stream.write('**** THREAD %d **** \n' % (i,)) for line in traceback.format_stack(frame): stream.write(line) return True
print 'launching daemon thread...', T().start() print 'done' print 'launching self-deadlocking thread...', U().start() print 'done' print 'launching thread that will die before the end...', v = V() v.start() print 'done' time.sleep(5) # Python 2.2 does not support threadframe.dict() if sys.hexversion < 0x02030000: frames = threadframe.threadframe() else: frames = threadframe.dict() # signal the thread V to die, then wait for it to oblige V_event.set() v.join() if sys.hexversion < 0x02030000: for frame in frames: print '-' * 72 print 'frame ref count = %d' % sys.getrefcount(frame) traceback.print_stack(frame) else: for thread_id, frame in frames.iteritems(): print '-' * 72