Helper to dump thread info.
(stream=None, show_pydevd_threads=True)
| 150 | |
| 151 | |
| 152 | def dump_threads(stream=None, show_pydevd_threads=True): |
| 153 | """ |
| 154 | Helper to dump thread info. |
| 155 | """ |
| 156 | if stream is None: |
| 157 | stream = sys.stderr |
| 158 | thread_id_to_name_and_is_pydevd_thread = {} |
| 159 | try: |
| 160 | threading_enumerate = _pydev_saved_modules.pydevd_saved_threading_enumerate |
| 161 | if threading_enumerate is None: |
| 162 | threading_enumerate = threading.enumerate |
| 163 | |
| 164 | for t in threading_enumerate(): |
| 165 | is_pydevd_thread = getattr(t, "is_pydev_daemon_thread", False) |
| 166 | thread_id_to_name_and_is_pydevd_thread[t.ident] = ( |
| 167 | "%s (daemon: %s, pydevd thread: %s)" % (t.name, t.daemon, is_pydevd_thread), |
| 168 | is_pydevd_thread, |
| 169 | ) |
| 170 | except: |
| 171 | pass |
| 172 | |
| 173 | stream.write("===============================================================================\n") |
| 174 | stream.write("Threads running\n") |
| 175 | stream.write("================================= Thread Dump =================================\n") |
| 176 | stream.flush() |
| 177 | |
| 178 | for thread_id, frame in _tid_to_frame_for_dump_threads().items(): |
| 179 | name, is_pydevd_thread = thread_id_to_name_and_is_pydevd_thread.get(thread_id, (thread_id, False)) |
| 180 | if not show_pydevd_threads and is_pydevd_thread: |
| 181 | continue |
| 182 | |
| 183 | stream.write("\n-------------------------------------------------------------------------------\n") |
| 184 | stream.write(" Thread %s" % (name,)) |
| 185 | stream.write("\n\n") |
| 186 | |
| 187 | for i, (filename, lineno, name, line) in enumerate(traceback.extract_stack(frame)): |
| 188 | stream.write(' File "%s", line %d, in %s\n' % (filename, lineno, name)) |
| 189 | if line: |
| 190 | stream.write(" %s\n" % (line.strip())) |
| 191 | |
| 192 | if i == 0 and "self" in frame.f_locals: |
| 193 | stream.write(" self: ") |
| 194 | try: |
| 195 | stream.write(str(frame.f_locals["self"])) |
| 196 | except: |
| 197 | stream.write("Unable to get str of: %s" % (type(frame.f_locals["self"]),)) |
| 198 | stream.write("\n") |
| 199 | stream.flush() |
| 200 | |
| 201 | stream.write("\n=============================== END Thread Dump ===============================") |
| 202 | stream.flush() |
| 203 | |
| 204 | |
| 205 | def _extract_variable_nested_braces(char_iter): |