IPyhon dies with recompiled macro

Dear all,

Though I wonder if I should simply address this to Wim :slight_smile:

I’m starting to use IPython to run my mixed C++/python/ROOT analysis, as I saw that it’s the most commonly used tool for pyroot users. When I reload a C++ class via gROOT, IPython gets confused and normally crashes when I try to use the changed class. An example is below.
In plain python, one can’t unload / reload libraries, so I’m used to simply exiting the python prompt and restarting (with an init macro). IPython’s approach seems to be that it is possible to unload modules, so development can proceed without existing the IPython environment. Can this be made to work with pyroot?

(I will be perfectly happy with an answer of “no”. Frankly, I still amazed at all the things that do work with pyroot.)


[quote]$ ipython
In [1]: import ROOT as R
In [2]: R.gROOT.LoadMacro(‘test_ip.h+’)
In [3]: tt = R.tip()
In [4]: R.gROOT.LoadMacro(‘test_ip.h++’)
In [5]: tt.method()
terminate called after throwing an instance of 'std::length_error’
what(): vector::_M_fill_insert

Where test_ip.h is simply:


using std::endl;
using std::cout;

class tip
int _foo;
double _bar;

void method()
cout<<"tip::method called. foobar are: “<<_foo<<”, "<<_bar<<endl;
Amnon Harel,
University of Rochester


I’m probably misunderstanding a couple of things here. For example, python can reload modules just fine (just use the builtin function “reload”). Reloading of libraries (i.e. C or C++ extension modules) does not work with either, as python keeps a ref-count of 1 on the dll.

The (pyroot) problem here is that the underlying TClass changes and pyroot does not pick that up (in fact, TClassRef does not even pick it up, even as it should). Has been long on the wish list to fix that, but no cycles available to work on that.

To be specific, what happens here is that the old class is fixed by instantiating the “tip”, but the method does not get resolved until it is actually used the first time. But then the old class is gone. If you were the use the method before reloading, it’d work fine both before and after, but it would always be the old method.

(If TClassRef would properly be updated, del R.tip and reinstantiating tt would’ve done the trick.)