1 #############################################################################
3 # Copyright 2007 Jose Fonseca
5 # This program is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as published
7 # by the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #############################################################################
20 '''Debugging utilities.'''
28 def excepthook(type, value, tb):
30 Automatically start the debugger on an exception.
33 - http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65287
36 if hasattr(sys, 'ps1') \
37 or not (sys.stdin.isatty() and sys.stdout.isatty() and sys.stderr.isatty()) \
38 or type == SyntaxError or type == KeyboardInterrupt:
39 # we are in interactive mode or we don't have a tty-like
40 # device, so we call the default hook
41 oldexcepthook(type, value, tb)
44 # we are NOT in interactive mode, print the exception...
45 traceback.print_exception(type, value, tb)
47 # ...then start the debugger in post-mortem mode.
50 oldexcepthook, sys.excepthook = sys.excepthook, excepthook
54 sys.stderr.write(repr(var) + '\n')