4

I have the following class definition in a py file:

class this_obj(object):

    def __init__(self):
         self._apple = 5.0
         self.observ_apple = []

    def setter(self, value):
        if (self._apple != value):
            self._apple = value
            for callback in self.observ_apple:
                callback(self._apple)

    def getter(self):
        return self._apple

    # apply property
    apple = property(getter, setter)

    # binder functions
    def bind_to_apple(self, callback):
        self.observ_apple.append(callback)

And I have this main code in another file:

import handler_obj

def print_on_change(value):
    print("apple change!!! " + str(value))

if __name__ == "__main__":
    q = handler_obj.this_obj()
    q.bind_to_apple(print_on_change)
    print(q.getter())
    q.setter(30)
    print(q.getter())

If you run this code you can see that it is running. Now I am trying to run the same code with Pyro4. As I was doing this I always run into the following error message:

Pyro4.errors.SerializeError: unsupported serialized class: builtins.function

for the following line:

q.bind_to_apple(print_on_change)

My question would be: Is this even possible with Pyro4 or is this a restriction of the serializer? Can this be solved if I try to use pickle instead of serpent?

If not than is there an alternative to Pyro4 which you can suggest for me for such cases?

Thanks in advance.

bdvd
  • 117
  • 1
  • 1
  • 11

1 Answers1

2

I just found a solution for that. If you change the serializer setting the Pyro4.config.SERIALIZER global variable to "dill", then the function callbacks will be handled too.

Gustavo Meira
  • 2,875
  • 3
  • 21
  • 33
bdvd
  • 117
  • 1
  • 1
  • 11
  • Don't edit the configuration.py file itself, as it is part of the library! Use another way to change the config item (for instance by using the appropriate environment variable) – Irmen de Jong May 08 '16 at 11:03