diff --git a/src/pykka/_proxy.py b/src/pykka/_proxy.py index 3371704..0c06fed 100644 --- a/src/pykka/_proxy.py +++ b/src/pykka/_proxy.py @@ -139,7 +139,10 @@ def __init__( msg = f"{actor_ref} not found" raise ActorDeadError(msg) self.actor_ref = actor_ref - self._actor = actor_ref._actor # noqa: SLF001 + self._actor = actor_ref._actor_weakref() # noqa: SLF001 + if self._actor is None: + msg = f"{actor_ref} not found (weakref has been deallocated)" + raise ActorDeadError(msg) self._attr_path = attr_path or () self._known_attrs = introspect_attrs(root=self._actor, proxy=self) self._actor_proxies = {} diff --git a/src/pykka/_ref.py b/src/pykka/_ref.py index 7ca8677..4eadc63 100644 --- a/src/pykka/_ref.py +++ b/src/pykka/_ref.py @@ -1,5 +1,6 @@ from __future__ import annotations +import weakref from typing import ( TYPE_CHECKING, Any, @@ -51,7 +52,7 @@ def __init__( self, actor: A, ) -> None: - self._actor = actor + self._actor_weakref = weakref.ref(actor) self.actor_class = actor.__class__ self.actor_urn = actor.actor_urn self.actor_inbox = actor.actor_inbox