0

I want to send lean object to another machine for execution of selected method.

I have a class like:

class ToBeSent:
    def __init__(self, data_info):
        self.data_info = data_info
    
    def use_data_info_common(self, other_data):
        print('using data info ' + self.data_info + other_data)

    def use_data_info_SERIALIZE(self, other_data):
        print('using data info ' + self.data_info + other_data)


    def use_data_info_NOT_serialize(self, other_data):
        # some other dependencies I don't want
        print("refers to bunch of methods and dependencies I don't want" + self.data_info + other_data)

    def serialize_me(self, other_data):
        self.use_data_info_common('other' + other_data)
        self.use_data_info_SERIALIZE('something')


    def NOT_serialize_me(self, other):
        self.use_data_info_common(other)
        self.use_data_info_NOT_serialize(other)

I want to serialize only one method serialize_me with all it's dependencies from this object (or super.object) but not the NOT_serialize_me and it's dependencies, because they are user defined and I cannot run them on target machine.

In case above I would like to automatically detect and serialize serialize_me and all dependencies which are:

  • use_data_info_SERIALIZE
  • use_data_info_common
  • self.data_info

and remove everything else:

  • NOT_serialize_me
  • use_data_info_NOT_serialize

I was experimenting with a proxy getattr trying to record all calls but it doesn't see any internal calls to common or other methods, and I was cutting too much from this class.

pprzemek
  • 2,455
  • 3
  • 25
  • 25
  • When you say you want to serialize some methods, but not others... what exactly do you mean? Do you mean that when the class instance is dumped... that the corresponding loaded class does not include the two methods that you want "removed"? – Mike McKerns Dec 20 '21 at 13:46
  • @MikeMcKerns yes, pretty much that's it, it want to send object to be executed on another machine, but some of the methods of this objects have terrible dependencies I have no way to detect and install automatically (and would have to fix every task to be executed) and there isn't standard protocol defined for this system, just a method that I need to call on different machines from a given object – pprzemek Dec 20 '21 at 16:12
  • This isn't a `dill/pickle` solution, but what you potentially could do is to create a base class that has all of the state and methods you'd like to serialize, and then a derived class that has everything. Then you'd just transfer the state (e.g. the `__dict__`) of the derived class instance to the base class instance, and send the base class instance across the `map`. – Mike McKerns Dec 20 '21 at 20:34

0 Answers0