irmen / Pyro5

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

Unexpected AttributeError when deleting Proxy #17

Closed samschott closed 4 years ago

samschott commented 4 years ago

In rare cases, an unexpected error is raised when a Proxy instance gets deleted / garbage collected:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/Pyro5/client.py", line 80, in __del__
AttributeError: 'NoneType' object has no attribute 'suppress'

The relevant line in Pyro4.client.Proxy is:

with contextlib.suppress(Exception):
    self._pyroRelease()

This issue has been introduced with 217af7b11b6a4f7231bbe88df2bd197d35ca839a and seems to only occur when exiting the interpreter.

irmen commented 4 years ago

Hmm, these kind of obscure errors make me think that implementing __del__ is maybe not worth the hassle..... On the other hand I'd really like Pyro to free resources it doesn't need anymore when a proxy gets destroyed...

In my experience, this particular type of error indeed only occurs when the whole interpreter is shutting down. I don't really like sprinkling all sorts of extra attribute / None checks in the del method, but maybe that's the only way to prevent these kind of errors from leaking out

samschott commented 4 years ago

Yes, I fully understand. And it’s a very rare issue.

A possible alternative to implementing ˋdelˋ with proper checks and exception handling may be to provide a context manager, i.e., ˋenterˋ and ˋexitˋ methods. But it would only be practical if the Proxy is only used temporarily.

This is actually how I am using Pyro Proxies myself at the moment.

irmen commented 4 years ago

Those context manager methods are already present.

samschott commented 4 years ago

Right, somehow I had overlooked that.