Skip to content
This repository

Don't attempt to tokenize binary files for tracebacks #1341

Merged
merged 3 commits into from about 2 years ago

3 participants

Thomas Kluyver Min RK Fernando Perez
Thomas Kluyver
Collaborator

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 (should I add any more to this list?).

Closes gh-1317

Min RK
Owner

Why blacklist binaries instead of whitelisting '.py'?

Thomas Kluyver
Collaborator

That's probably a better way to do it.

Thomas Kluyver
Collaborator

I think .py, .pyw, .pyc and .pyo cover all the files that we should attempt to tokenise.

Fernando Perez
Owner

Hold on, what about extensionless-files? It's perfectly valid to call %run foo if foo is a python script with no extension. Will this still work in that case?

Thomas Kluyver
Collaborator

It didn't - reverted to a blacklist.

Fernando Perez
Owner

Much better, merging. Thanks!

Fernando Perez fperez merged commit a1769ad into from January 29, 2012
Fernando Perez fperez closed this January 29, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 8 additions and 2 deletions. Show diff stats Hide diff stats

  1. 10  IPython/core/ultratb.py
10  IPython/core/ultratb.py
@@ -823,10 +823,16 @@ def nullrepr(value, repr=text_repr): return ''
823 823
                     # will illustrate the error, if this exception catch is
824 824
                     # disabled.
825 825
                     call = tpl_call_fail % func
  826
+            
  827
+            # Don't attempt to tokenize binary files.
  828
+            if file.endswith(('.so', '.pyd', '.dll')):
  829
+                frames.append('%s %s\n' % (link,call))
  830
+                continue
  831
+            elif file.endswith(('.pyc','.pyo')):
  832
+                # Look up the corresponding source file.
  833
+                file = pyfile.source_from_cache(file)
826 834
 
827 835
             def linereader(file=file, lnum=[lnum], getline=linecache.getline):
828  
-                if file.endswith(('.pyc','.pyo')):
829  
-                    file = pyfile.source_from_cache(file)
830 836
                 line = getline(file, lnum[0])
831 837
                 lnum[0] += 1
832 838
                 return line
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.