From f843b32e882516b5c3fa25d82822715fc0e1bad1 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sun, 24 Mar 2013 00:24:13 +0100 Subject: [PATCH] Turn thread traceback logger on by default It no longer requires an additional thread to work and it is very useful to have this enabled when you hit an issue that is hard to reproduce. --- docs/changes.rst | 5 +++++ docs/development.rst | 25 +++++++++++++++++++++---- mopidy/__main__.py | 4 +--- mopidy/settings.py | 8 -------- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 776aada4..47786a56 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -19,6 +19,11 @@ v0.13.0 (in development) - Log a warning if a track isn't playable to make it more obvious that backend X needs backend Y to be present for playback to work. +- Removed the :attr:`mopidy.settings.DEBUG_THREAD` setting and the + :option:`--debug-thread` command line option. Sending SIGUSR1 to + the Mopidy process will now always make it log tracebacks for all alive + threads. + **Spotify backend** - Let GStreamer handle time position tracking and seeks. (Fixes: :issue:`191`) diff --git a/docs/development.rst b/docs/development.rst index 1211cec4..a0392f81 100644 --- a/docs/development.rst +++ b/docs/development.rst @@ -305,10 +305,27 @@ Debugging deadlocks Between the numerous Pykka threads and GStreamer interactions there can sometimes be a potential for deadlocks. In an effort to make these slightly -simpler to debug the setting :attr:`mopidy.settings.DEBUG_THREAD` or the option -``--debug-thread`` can be used to turn on an extra debug thread. This thread is -not linked to the regular program flow, and it's only task is to dump traceback -showing the other threads state when we get a ``SIGUSR1``. +simpler to debug Mopidy registers a ``SIGUSR1`` signal handler which logs the +traceback of all alive threads. + +To trigger the signal handler, you need the process ID (PID) of Mopidy. This +can for example be found by running ``ps``:: + + $ ps aux | grep mopidy + jodal 4313 2.0 1.7 2573592 69804 pts/14 Sl+ 00:15 0:02 python + mopidy + jodal 4700 0.0 0.0 9392 924 pts/10 S+ 00:17 0:00 grep + mopidy + $ + +In this example, Mopidy's PID is 4313. You can then use the ``kill`` command to +send the ``SIGUSR1`` signal to the Mopidy proces:: + + $ kill -SIGUSR1 4313 + $ + +If you check the log, you should now find one log record with a full traceback +for each of the currently alive threads in Mopidy. Writing documentation diff --git a/mopidy/__main__.py b/mopidy/__main__.py index 5c049daf..a7e914a9 100644 --- a/mopidy/__main__.py +++ b/mopidy/__main__.py @@ -45,13 +45,11 @@ logger = logging.getLogger('mopidy.main') def main(): signal.signal(signal.SIGTERM, process.exit_handler) + signal.signal(signal.SIGUSR1, pykka.debug.log_thread_tracebacks) loop = gobject.MainLoop() options = parse_options() - if options.debug_thread or settings.DEBUG_THREAD: - signal.signal(signal.SIGUSR1, pykka.debug.log_thread_tracebacks) - try: log.setup_logging(options.verbosity_level, options.save_debug_log) check_old_folders() diff --git a/mopidy/settings.py b/mopidy/settings.py index fd3dfd6f..c7c5bb4c 100644 --- a/mopidy/settings.py +++ b/mopidy/settings.py @@ -49,14 +49,6 @@ DEBUG_LOG_FORMAT = '%(levelname)-8s %(asctime)s' + \ #: DEBUG_LOG_FILENAME = u'mopidy.log' DEBUG_LOG_FILENAME = 'mopidy.log' -#: If we should start a background thread that dumps thread's traceback when we -#: get a SIGUSR1. Mainly a debug tool for figuring out deadlocks. -#: -#: Default:: -#: -#: DEBUG_THREAD = False -DEBUG_THREAD = False - #: Location of the Mopidy .desktop file. #: #: Used by :mod:`mopidy.frontends.mpris`.