mirror of
https://github.com/rembo10/headphones.git
synced 2026-05-09 13:19:28 +01:00
Add a thread-dumping handler
Add a 'crier' handler to dump the thread stacks of running threads to the log, for easier debugging.
This commit is contained in:
36
headphones/crier.py
Normal file
36
headphones/crier.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import pprint
|
||||
import sys
|
||||
import threading
|
||||
import traceback
|
||||
|
||||
from headphones import logger
|
||||
|
||||
|
||||
def cry():
|
||||
"""
|
||||
Logs thread traces.
|
||||
"""
|
||||
tmap = {}
|
||||
main_thread = None
|
||||
# get a map of threads by their ID so we can print their names
|
||||
# during the traceback dump
|
||||
for t in threading.enumerate():
|
||||
if t.ident:
|
||||
tmap[t.ident] = t
|
||||
else:
|
||||
main_thread = t
|
||||
|
||||
# Loop over each thread's current frame, writing info about it
|
||||
for tid, frame in sys._current_frames().iteritems():
|
||||
thread = tmap.get(tid, main_thread)
|
||||
|
||||
lines = []
|
||||
lines.append('%s\n' % thread.getName())
|
||||
lines.append('========================================\n')
|
||||
lines += traceback.format_stack(frame)
|
||||
lines.append('========================================\n')
|
||||
lines.append('LOCAL VARIABLES:\n')
|
||||
lines.append('========================================\n')
|
||||
lines.append(pprint.pformat(frame.f_locals))
|
||||
lines.append('\n\n')
|
||||
logger.info("".join(lines))
|
||||
@@ -28,7 +28,7 @@ import urllib2
|
||||
|
||||
import os
|
||||
import re
|
||||
from headphones import logger, searcher, db, importer, mb, lastfm, librarysync, helpers, notifiers
|
||||
from headphones import logger, searcher, db, importer, mb, lastfm, librarysync, helpers, notifiers, crier
|
||||
from headphones.helpers import checked, radio, today, clean_name
|
||||
from mako.lookup import TemplateLookup
|
||||
from mako import exceptions
|
||||
@@ -69,6 +69,11 @@ class WebInterface(object):
|
||||
artists = myDB.select('SELECT * from artists order by ArtistSortName COLLATE NOCASE')
|
||||
return serve_template(templatename="index.html", title="Home", artists=artists)
|
||||
|
||||
@cherrypy.expose
|
||||
def threads(self):
|
||||
crier.cry()
|
||||
raise cherrypy.HTTPRedirect("home")
|
||||
|
||||
@cherrypy.expose
|
||||
def artistPage(self, ArtistID):
|
||||
myDB = db.DBConnection()
|
||||
|
||||
Reference in New Issue
Block a user