| 112 | |
| 113 | |
| 114 | def dump_stacks(signal=None, frame=None, file=sys.stdout): |
| 115 | id2name = {th.ident: th.name for th in threading.enumerate()} |
| 116 | code = [] |
| 117 | for threadId, stack in sys._current_frames().items(): |
| 118 | code.append("\n# Thread: %s(%d)" % (id2name.get(threadId, ""), threadId)) |
| 119 | for filename, lineno, name, line in traceback.extract_stack(stack): |
| 120 | code.append('File: "%s", line %d, in %s' % (filename, lineno, name)) |
| 121 | if line: |
| 122 | code.append(" %s" % (line.strip())) |
| 123 | print("\n".join(code), file=file) |
| 124 | if os.getenv("MITMPROXY_DEBUG_EXIT"): # pragma: no cover |
| 125 | sys.exit(1) |
| 126 | |
| 127 | |
| 128 | def register_info_dumpers(): |