irmen / Pyro5

Pyro 5 - Python remote objects
https://pyro5.readthedocs.io
MIT License
305 stars 36 forks source link

'method_descriptor' object has no attribute ... #41

Closed tlambert03 closed 3 years ago

tlambert03 commented 3 years ago

Hi, thanks for a very cool looking library. I'm eager to give it a shot. I'm trying to expose a SWIG-generated object (of type SwigPyObjectType)... and running into issues during api.expose when pyro tries to assign various attributes on the members of the class:

File "~/miniconda3/envs/napdev/lib/python3.9/site-packages/Pyro5/server.py", line 102, in expose
  thing._pyroExposed = True
AttributeError: 'method_descriptor' object has no attribute '_pyroExposed'

I assume this is somewhat specific to SWIG-generated objects, but I assume this "has no attribute" challenge has probably come up in other contexts. I'm wondering if you have any suggestions for a workaround?

If you want to try the exact object I'm trying to expose: pip install pymmcore

import Pyro5.api
from pymmcore import CMMCore as _CMMCore
CMMCore = Pyro5.api.expose(_CMMCore)

thanks!

irmen commented 3 years ago

seems to me that that CMMCore class has slots in it, that restrict the possible attributes on the object. Nothing we can do about it directly. Can you check that? You'll have to wrap the class in one without slots to make it work with Pyro I think.

tlambert03 commented 3 years ago

thanks for your response. I did actually try wrapping in another class and playing with both __slots__ and __dict__. I got it so that the class itself could accept attributes, but it still didn't work when pyro tried to add attributes directly to the members of the class (it still led to the method_descriptor problem)... I'll keep playing around. thanks again

irmen commented 3 years ago

A "normal" python class doesn't have this issue so Swig is really doing something funky

tlambert03 commented 3 years ago

Yep, I recognize that. Just wondered if it was something you'd encountered. From your experience, can you imagine any other way to implement those few _Pyro attributes rather than modifying the user object itself?

irmen commented 3 years ago

This is how Pyro works internally. It rarely is a problem. Create a normal wrapper class and delegate the methods and properties to that weird swig class, and you'll be fine.

tlambert03 commented 3 years ago

Thanks for your time

irmen commented 3 years ago

no problem!