Skip to content

Commit

Permalink
Merge pull request ipython#1341 from takluyver/i1317
Browse files Browse the repository at this point in the history
Don't attempt to tokenize binary files for tracebacks.

Previously we had been trying and just catching the exception, but in corner cases the tokenizer can run for several seconds before raising an exception (ipython#1317). This skips tokenizing if the file has the extension .so, .pyd or .dll.

Closes ipythongh-1317.
  • Loading branch information
fperez committed Jan 29, 2012
2 parents 7379572 + fbef7f1 commit c43f792
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions IPython/core/ultratb.py
Expand Up @@ -823,10 +823,16 @@ def nullrepr(value, repr=text_repr): return ''
# will illustrate the error, if this exception catch is
# disabled.
call = tpl_call_fail % func

# Don't attempt to tokenize binary files.
if file.endswith(('.so', '.pyd', '.dll')):
frames.append('%s %s\n' % (link,call))
continue
elif file.endswith(('.pyc','.pyo')):
# Look up the corresponding source file.
file = pyfile.source_from_cache(file)

def linereader(file=file, lnum=[lnum], getline=linecache.getline):
if file.endswith(('.pyc','.pyo')):
file = pyfile.source_from_cache(file)
line = getline(file, lnum[0])
lnum[0] += 1
return line
Expand Down

0 comments on commit c43f792

Please sign in to comment.