MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / _start_monitoring_threads

Function _start_monitoring_threads

conftest.py:45–98  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

43
44
45def _start_monitoring_threads():
46 # After the session finishes, wait 20 seconds to see if everything finished properly
47 # and if it doesn't report an error.
48 global _started_monitoring_threads
49 if _started_monitoring_threads:
50 return
51
52 _started_monitoring_threads = True
53 import threading
54
55 if hasattr(sys, "_current_frames") and hasattr(threading, "enumerate"):
56 import time
57 import traceback
58
59 class DumpThreads(threading.Thread):
60 def run(self):
61 time.sleep(20)
62
63 thread_id_to_name = {}
64 try:
65 for t in threading.enumerate():
66 thread_id_to_name[t.ident] = "%s (daemon: %s)" % (t.name, t.daemon)
67 except:
68 pass
69
70 stack_trace = [
71 "===============================================================================",
72 "pydev pyunit runner: Threads still found running after tests finished",
73 "================================= Thread Dump =================================",
74 ]
75
76 for thread_id, stack in sys._current_frames().items():
77 stack_trace.append("\n-------------------------------------------------------------------------------")
78 stack_trace.append(" Thread %s" % thread_id_to_name.get(thread_id, thread_id))
79 stack_trace.append("")
80
81 if "self" in stack.f_locals:
82 sys.stderr.write(str(stack.f_locals["self"]) + "\n")
83
84 for filename, lineno, name, line in traceback.extract_stack(stack):
85 stack_trace.append(' File "%s", line %d, in %s' % (filename, lineno, name))
86 if line:
87 stack_trace.append(" %s" % (line.strip()))
88 stack_trace.append("\n=============================== END Thread Dump ===============================")
89 sys.stderr.write("\n".join(stack_trace))
90
91 # Force thread run to finish
92 import os
93
94 os._exit(123)
95
96 dump_current_frames_thread = DumpThreads()
97 dump_current_frames_thread.daemon = True # Daemon so that this thread doesn't halt it!
98 dump_current_frames_thread.start()
99
100
101def pytest_unconfigure():

Callers 2

pytest_unconfigureFunction · 0.85
check_no_threadsFunction · 0.85

Calls 2

DumpThreadsClass · 0.70
startMethod · 0.45

Tested by

no test coverage detected