| 301 | |
| 302 | class DumpThreads(threading.Thread): |
| 303 | def run(self): |
| 304 | time.sleep(10) |
| 305 | |
| 306 | thread_id_to_name = {} |
| 307 | try: |
| 308 | for t in threading.enumerate(): |
| 309 | thread_id_to_name[t.ident] = "%s (daemon: %s)" % (t.name, t.daemon) |
| 310 | except: |
| 311 | pass |
| 312 | |
| 313 | stack_trace = [ |
| 314 | "===============================================================================", |
| 315 | "pydev pyunit runner: Threads still found running after tests finished", |
| 316 | "================================= Thread Dump =================================", |
| 317 | ] |
| 318 | |
| 319 | for thread_id, stack in sys._current_frames().items(): |
| 320 | stack_trace.append("\n-------------------------------------------------------------------------------") |
| 321 | stack_trace.append(" Thread %s" % thread_id_to_name.get(thread_id, thread_id)) |
| 322 | stack_trace.append("") |
| 323 | |
| 324 | if "self" in stack.f_locals: |
| 325 | sys.stderr.write(str(stack.f_locals["self"]) + "\n") |
| 326 | |
| 327 | for filename, lineno, name, line in traceback.extract_stack(stack): |
| 328 | stack_trace.append(' File "%s", line %d, in %s' % (filename, lineno, name)) |
| 329 | if line: |
| 330 | stack_trace.append(" %s" % (line.strip())) |
| 331 | stack_trace.append("\n=============================== END Thread Dump ===============================") |
| 332 | sys.stderr.write("\n".join(stack_trace)) |
| 333 | |
| 334 | dump_current_frames_thread = DumpThreads() |
| 335 | dump_current_frames_thread.daemon = True # Daemon so that this thread doesn't halt it! |