Skip to content

Commit

Permalink
Add faulthandler module support for debugging hangs/segfaults
Browse files Browse the repository at this point in the history
- No-op if not present
  • Loading branch information
virtuald committed Apr 15, 2017
1 parent 02cbdc0 commit c17bf04
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/dev/debugging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ On Linux/OSX:

TODO: Windows

Viewing stack traces when Exaile hangs
--------------------------------------

If you have the `faulthandler <https://github.com/haypo/faulthandler>`_ module
installed, on Linux/OSX if you send SIGUSR2 to Exaile it will dump stacktraces
of all current Python threads to stderr.

GStreamer Debugging Techniques
------------------------------
Expand Down
14 changes: 14 additions & 0 deletions xl/logger_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ def log_unhandled_exception(*args):
logger.error("Unhandled exception", exc_info=args)

sys.excepthook = log_unhandled_exception

# Strictly speaking, this isn't logging, but it's useful for debugging
# when Exaile hangs. Requires the 'faulthandler' module to be installed
# from pip on python2, comes with python 3.3+
try:
import faulthandler
except ImportError:
pass
else:
# Windows doesn't allow custom fault handler registration
if hasattr(faulthandler, 'register'):
import signal
faulthandler.register(signal.SIGUSR2)
faulthandler.enable()

def stop_logging():
logging.shutdown()
Expand Down

0 comments on commit c17bf04

Please sign in to comment.