forked from thewca/tnoodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tntdebug.py
45 lines (40 loc) · 1.69 KB
/
tntdebug.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Terribly useful debugging tweaks
import os
import sys
import pdb
import cgitb
import traceback
if sys.executable is None:
# If sys.executable is None, it will cause an exception inside of
# cgitb at this line:
# pyver = 'Python ' + sys.version.split()[0] + ': ' + sys.executable
sys.executable = "Jython?"
try:
from java.lang import Throwable
from net.gnehzr.tnoodle.utils import TNoodleLogging
TNoodleLogging.initializeLogging()
except ImportError:
Throwable = None
# Do nothing, we're just running in pure python
pass
def excepthook(etype, value, tb):
# Added this line for debugging why https://travis-ci.org/cubing/tnoodle/builds/15966902
# hit pdb instead of just printing a traceback and exiting.
# Once that problem is solved, we can delete this code.
print("Hit excepthook! stderr.isatty: %s stdin.isatty: %s stdout.isatty: %s" % (sys.stderr.isatty(), sys.stdin.isatty(), sys.stdout.isatty()))
# Workaround for isatty weirdness mentioned above.
isTravisCiBuild = os.environ.get('TRAVIS_BRANCH', None)
if not sys.stdout.isatty() or not sys.stderr.isatty() or not sys.stdin.isatty() or isTravisCiBuild:
# We're not running interactively, so don't enter PDB.
sys.stderr.write(cgitb.text((etype, value, tb)))
while tb.tb_next:
tb = tb.tb_next
sys.stderr.write("Globals: {}\n".format(tb.tb_frame.f_locals))
sys.stderr.write("Locals: {}\n".format(tb.tb_frame.f_locals))
else:
if tb:
traceback.print_exception(etype, value, tb)
if Throwable and issubclass(etype, Throwable):
value.printStackTrace()
pdb.post_mortem(tb)
sys.excepthook = excepthook