提交 42c00fb2 authored 作者: Frederic Bastien's avatar Frederic Bastien

make sure to always have at least one user stack trace and don't check the stack for more then one

上级 3adaa82f
...@@ -10,7 +10,7 @@ from theano import config ...@@ -10,7 +10,7 @@ from theano import config
from theano.compat import OrderedDict, PY3 from theano.compat import OrderedDict, PY3
def simple_extract_stack(f=None, limit=None): def simple_extract_stack(f=None, limit=None, skips=[]):
""" """
This is traceback.extract_stack from python 2.7 with this change: This is traceback.extract_stack from python 2.7 with this change:
...@@ -19,6 +19,8 @@ def simple_extract_stack(f=None, limit=None): ...@@ -19,6 +19,8 @@ def simple_extract_stack(f=None, limit=None):
This is because this update cause an call to os.stat to get the This is because this update cause an call to os.stat to get the
line content. This cause too much long on cluster. line content. This cause too much long on cluster.
skips - partial path of stack level we don't want to keep and count.
When we find one level that isn't skipped, we stop skipping.
""" """
if f is None: if f is None:
try: try:
...@@ -41,8 +43,20 @@ def simple_extract_stack(f=None, limit=None): ...@@ -41,8 +43,20 @@ def simple_extract_stack(f=None, limit=None):
line = line.strip() line = line.strip()
else: else:
line = None line = None
list.append((filename, lineno, name, line))
f = f.f_back f = f.f_back
if len(list) == 0:
rm = False
for p in skips:
# Julian: I added the 'tests' exception together with
# Arnaud. Otherwise, we'd lose the stack trace during
# in our test cases (e.g. in test_opt.py). We're not
# sure this is the right way to do it though.
if p in filename and 'tests' not in filename:
rm = True
break
if rm:
continue
list.append((filename, lineno, name, line))
n = n + 1 n = n + 1
list.reverse() list.reverse()
return list return list
...@@ -76,39 +90,19 @@ def add_tag_trace(thing, user_line=1): ...@@ -76,39 +90,19 @@ def add_tag_trace(thing, user_line=1):
limit = config.traceback.limit limit = config.traceback.limit
if limit == -1: if limit == -1:
limit = None limit = None
tr = simple_extract_stack(limit=limit)[:-1] skips = ["theano/tensor/", "theano\\tensor\\",
# Different python version use different sementic for
# limit. python 2.7 include the call to extrack_stack. The -1 get
# rid of it.
# Get rid of Theano internal
while tr:
file_path = tr[-1][0]
rm = False
for p in ["theano/tensor/", "theano\\tensor\\",
"theano/compile/", "theano\\compile\\", "theano/compile/", "theano\\compile\\",
"theano/gof/", "theano\\gof\\", "theano/gof/", "theano\\gof\\",
"theano/scalar/basic.py", "theano\\scalar\\basic.py", "theano/scalar/basic.py", "theano\\scalar\\basic.py",
"theano/sandbox/", "theano\\sandbox\\", "theano/sandbox/", "theano\\sandbox\\",
"theano/scan_module/", "theano\\scan_module\\", "theano/scan_module/", "theano\\scan_module\\",
"theano/sparse/", "theano\\sparse\\", "theano/sparse/", "theano\\sparse\\",
"theano/typed_list/", "theano\\typed_list\\", "theano/typed_list/", "theano\\typed_list\\",]
]: tr = simple_extract_stack(limit=user_line, skips=skips)
# Julian: I added the 'tests' exception together with Arnaud. # Different python version use different sementic for
# Otherwise, we'd lose the stack trace during in our test cases # limit. python 2.7 include the call to extrack_stack. The -1 get
# (e.g. in test_opt.py). We're not sure this is the right way to # rid of it.
# do it though.
if p in file_path and 'tests' not in file_path:
tr = tr[:-1]
rm = True
break
if not rm:
break
# Keep only the most recent stack level.
# The order is from the oldest to the newest
if len(tr) > user_line:
tr = tr[-user_line:]
if tr: if tr:
thing.tag.trace = [tr] thing.tag.trace = [tr]
else: else:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论