def stacktraces():
    """Taken from http://bzimmer.ziclix.com/2008/12/17/python-thread-dumps/"""
    code = []
    for thread_id, stack in sys._current_frames().items():
        thread = _thread_from_id(thread_id)
        code.append(f"\n# thread_id={thread_id}. thread={thread}")
        for filename, lineno, name, line in traceback.extract_stack(stack):
            code.append(f'File: "{filename}", line {lineno}, in {name}')
            if line:
                code.append("  %s" % (line.strip()))

    return highlight("\n".join(code), PythonLexer(), HtmlFormatter(
        full=False,
        # style="native",
        noclasses=True,
    ))
Taken from http://bzimmer.ziclix.com/2008/12/17/python-thread-dumps/
electrum/utils/stacktracer.py