Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
fd796478
Commit
fd796478
authored
Aug 02, 2012
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a handy supertrace script
parent
31b8270c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
0 deletions
+52
-0
common/lib/supertrace.py
+52
-0
No files found.
common/lib/supertrace.py
0 → 100644
View file @
fd796478
"""
A handy util to print a django-debug-screen-like stack trace with
values of local variables.
"""
import
sys
,
traceback
from
django.utils.encoding
import
smart_unicode
def
supertrace
(
max_len
=
160
):
"""
Print the usual traceback information, followed by a listing of all the
local variables in each frame. Should be called from an exception handler.
if max_len is not None, will print up to max_len chars for each local variable.
(cite: modified from somewhere on stackoverflow)
"""
tb
=
sys
.
exc_info
()[
2
]
while
True
:
if
not
tb
.
tb_next
:
break
tb
=
tb
.
tb_next
stack
=
[]
frame
=
tb
.
tb_frame
while
frame
:
stack
.
append
(
f
)
frame
=
frame
.
f_back
stack
.
reverse
()
# First print the regular traceback
traceback
.
print_exc
()
print
"Locals by frame, innermost last"
for
frame
in
stack
:
print
print
"Frame
%
s in
%
s at line
%
s"
%
(
frame
.
f_code
.
co_name
,
frame
.
f_code
.
co_filename
,
frame
.
f_lineno
)
for
key
,
value
in
frame
.
f_locals
.
items
():
print
(
"
\t
%20
s = "
%
smart_unicode
(
key
,
errors
=
'ignore'
)),
# We have to be careful not to cause a new error in our error
# printer! Calling str() on an unknown object could cause an
# error.
try
:
s
=
smart_unicode
(
value
,
errors
=
'ignore'
)
if
max_len
is
not
None
:
s
=
s
[:
max_len
]
print
s
except
:
print
"<ERROR WHILE PRINTING VALUE>"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment