object has no attribute '_myRef'

32 views
Skip to first unread message

Justin Paston-Cooper

unread,
Feb 28, 2021, 1:39:39 PM2/28/21
to thespian.py
Hello,

I am trying to run the following code using Python 3.7.3:

-------------------------------

from thespian.actors import *

class A(Actor):
    def receiveMessage(self, message, sender):
        if isinstance(message, ActorExitRequest):
            print("EXIT A")

class B(Actor):
    def __init__(self):
        self.A = self.createActor(A)

    def receiveMessage(self, message, sender):
        if isinstance(message, ActorExitRequest):
            print("EXIT B")

asys = ActorSystem('multiprocQueueBase')

bActor = asys.createActor(B)
asys.tell(bActor, ActorExitRequest)

------------------------------------

I get the following error:

AttributeError: 'B' object has no attribute '_myRef'

The error pertains to the call to self.createActor in the class B.

Could anyone tell me how to alleviate this error?

Thanks,

Justin

Kevin Quick

unread,
Feb 28, 2021, 2:34:00 PM2/28/21
to Justin Paston-Cooper, thespian.py
Hi Justin,

The problem here is that each Actor is not fully initialized until the __init__ method has completed, so attempting to call `createActor` in the __init__ of the B actor is failing because it's not ready to do actor things yet.

To fix this, I'd recommend an initialization message that gets sent to B to tell it to create the A actor, or alternatively the __init__ could set `self.A = None` and then in `receiveMessage`, if that value is still `None`, replace it with the `createActor` call value at that point.

Clearly, I've done a poor job of documenting this because even *I* can't find where I put this in the documentation! I'll add some additional documentation about this in the next release, and I'm sorry you got held up by this.

Regards,
  Kevin

--
You received this message because you are subscribed to the Google Groups "thespian.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thespianpy+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/thespianpy/0d4ba4d5-1ea9-4512-b8ae-978a089581f8n%40googlegroups.com.


--
-KQ

Justin Paston-Cooper

unread,
Feb 28, 2021, 2:36:34 PM2/28/21
to Kevin Quick, thespian.py
Hi Kevin,

Thanks for the quick reply. I will go with the second option for now.

Cheers,

J.

Justin Paston-Cooper

unread,
Feb 28, 2021, 2:42:27 PM2/28/21
to Kevin Quick, thespian.py
Actually I have a question regarding initialisation messages. Is there a standard message that is automatically sent to an actor once it is fully initialised so that it knows that it is initialised? If not, is it common to just create an "Initialize" class and send that as a first message to an actor?

On Sun, 28 Feb 2021 at 22:34, Kevin Quick <kq1q...@gmail.com> wrote:

Kevin Quick

unread,
Feb 28, 2021, 2:50:43 PM2/28/21
to Justin Paston-Cooper, thespian.py
No, there is no standard message: not all actors will necessarily need one, and some actors will need additional information in an initialization.  There is however an initmsgs helper that lets you use a decorator to hold other messages until the initialization message has been received, ensuring the initialization happens before handling other messages; see https://thespianpy.com/doc/using.html#h:5f80e194-ab38-406e-b077-984496b37073 for more details.

-Kevin

Justin Paston-Cooper

unread,
Feb 28, 2021, 2:54:37 PM2/28/21
to Kevin Quick, thespian.py
Thank you.
Reply all
Reply to author
Forward
0 new messages