'Dump Server threads for debugging'

@api.response(200, description=u'Flexget    threads    dump', model=dump_threads_schema)
def get(self, session=None):

    id2name = dict([(th.ident, th.name) for th in threading.enumerate()])
    threads = []
    for (threadId, stack) in sys._current_frames().items():
        dump = []
        for (filename, lineno, name, line) in traceback.extract_stack(stack):
            dump.append((u'File:    "%s",    line    %d,    in    %s' % (filename, lineno, name)))
            if line:
                dump.append(line.strip())
        threads.append({u'name': id2name.get(threadId), u'id': threadId, u'dump': dump})
    return jsonify(threads=threads)
