From a1769ad0bcb76dea9c6e4e0bd93f519649f1a814 2012-01-29 19:25:51 From: Fernando Perez Date: 2012-01-29 19:25:51 Subject: [PATCH] Merge pull request #1341 from takluyver/i1317 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 (#1317). This skips tokenizing if the file has the extension .so, .pyd or .dll. Closes gh-1317. --- diff --git a/IPython/core/ultratb.py b/IPython/core/ultratb.py index 61f5e6a..61ca205 100644 --- a/IPython/core/ultratb.py +++ b/IPython/core/ultratb.py @@ -823,10 +823,16 @@ class VerboseTB(TBTools): # 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