From: Barry S. <ba...@ba...> - 2016-04-27 20:15:46
|
> On 27 Apr 2016, at 20:24, kishor sharma <kis...@gm...> wrote: > > Hi CXX Users, > > I am using PyCXX to write extension classes. I am trying to pickle the extension object using cPickle. cPickle break as __module__ attribute is not on the objects > e.g. > > In [1]: import example > range object created 0x196b290 > range object destroyed 0x196b290 > > In [2]: example.range.__name__ > Out[2]: 'range' > > In [3]: example.range.__doc__ > Out[3]: 'range(start,stop,stride)' > > In [4]: example.range.__module__ > > In [5]: example.range.__module__ is None > Out[5]: True > > I tried debugging the code it seems to be passing correct module name to Py_InitModule4 function but it is not reflected in the python. > > Any help/pointers on how to fix? Its been a long time since I used pickle. Personally I would avoid pickle because of the security and robustness issues. Anyway. It looks like if you want to pickle an extension object you have to implement the __reduce__ and/or __reduce_ex__ methods. You would have to see what pickle does with the tuple returned by __reduce__ to recreate the objects. You can also register functions to assist pickle. Given that the reason a C++ extension module is created is to wrap around complex resources I wonder if its reasonable to attempt to pickle a C++ object. Barry > > Thanks, > Kishor Sharma > ------------------------------------------------------------------------------ > Find and fix application performance issues faster with Applications Manager > Applications Manager provides deep performance insights into multiple tiers of > your business applications. It resolves application problems quickly and > reduces your MTTR. Get your free trial! > https://ad.doubleclick.net/ddm/clk/302982198;130105516;z_______________________________________________ > CXX-Users mailing list > CXX...@li... > https://lists.sourceforge.net/lists/listinfo/cxx-users |