Pyro5 icon indicating copy to clipboard operation
Pyro5 copied to clipboard

Improve registration robustness for instances of registered classes

Open mawildoer opened this issue 1 year ago • 3 comments

I am trying to remotely control a very OO interface by leveraging Pyro5's autoproxying features

I implemented a version of this workaround in a util function in the module I was working on and thought the same case might cause issues for others too.

The issue arrises when you do something like:

from kigadgets.util import register_return
from Pyro5.api import expose, Daemon

daemon = Daemon()

@expose
class Returned(object):
    pass  # not important

daemon.register(Returned)

@expose
class Dummy(object):
    @property
    def thingo(self) -> Returned:
        result = Returned()
        self._pyroDaemon.register(result)
        return result

dummy = Dummy()
daemon.register(dummy)
dummy.thingo

mawildoer avatar Jan 31 '24 02:01 mawildoer

what exactly was the issue you encountered initially?

irmen avatar Feb 01 '24 19:02 irmen

If you try register an instance of a class that's already registered, it'll raise a DaemonError.

Seems to be because the _pyroId is inherited from the parent class, and is therefore already present, even if the instance itself is unregistered.

I don't want to blindly use force=True in this case because I'm connecting up a third-party lib that is going to return other instances of exposed classes.

mawildoer avatar Feb 02 '24 17:02 mawildoer

Could you perhaps add a unit test for this change as well? I think test_daemon.py could be the right place for it.

irmen avatar Feb 04 '24 15:02 irmen