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.)

Example:

[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
Aborted[/quote]

Where test_ip.h is simply:

[code]#include

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

class tip
{
public:
int _foo;
double _bar;

void method()
{
cout<<"tip::method called. foobar are: ā€œ<<_foo<<ā€, "<<_bar<<endl;
}
};
[/code]
thanks,
Amnon Harel,
University of Rochester

Amnon,

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.)

Cheers,
Wim