carlsborg / rcviz

Python call graph visualization for recursive functions.
217 stars 40 forks source link

Example code does not work with ipython #4

Closed stharding closed 10 months ago

stharding commented 8 years ago

I'm running OS X 10.11.4, using Anaconda. If I paste your sample code into a python shell, it works fine, but using the %paste magic function in ipython results in the error pasted below. I also tried it in an iPython Notebook--same result.

$ ipython
Python 2.7.11 |Anaconda 2.4.1 (x86_64)| (default, Dec  6 2015, 18:57:58)
Type "copyright", "credits" or "license" for more information.

IPython 4.0.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: %paste
from rcviz import callgraph, viz

@viz
def quicksort(items):
    if len(items) <= 1:
        return items
    else:
        pivot = items[0]
        lesser = quicksort([x for x in items[1:] if x < pivot])
        greater = quicksort([x for x in items[1:] if x >= pivot])
        return lesser + [pivot] + greater

print quicksort( list("helloworld") )
callgraph.render("sort.png")

## -- End pasted text --
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-1-2d0324c766ba> in <module>()
     11         return lesser + [pivot] + greater
     12
---> 13 print quicksort( list("helloworld") )
     14 callgraph.render("sort.png")

/Users/harding/anaconda/lib/python2.7/site-packages/rcviz-0.1-py2.7.egg/rcviz/rcviz.pyc in __call__(self, *args, **kwargs)
    172                 if caller_frame_id:
    173                         edgeinfo = [this_frame_id, callgraph.get_counter()]
--> 174                         g_callers[caller_frame_id].child_methods.append( edgeinfo )
    175                         callgraph.increment()
    176

KeyError: 4329494704

In [2]:
DamnedFacts commented 7 years ago

I've just completed an updated fork of this project to include Python3 Jupyter, and IPython support. https://github.com/DamnedFacts/rcviz

Naereen commented 3 years ago

Thank @DamnedFacts, your fork works perfectly fine for me on IPython 7.16.1 for Python 3.6.9 !

carlsborg commented 10 months ago

Really like @DamnedFacts fork, i am humbled that you found this useful :) I've revisited and added this feature with a bigger refactor.