Thespian icon indicating copy to clipboard operation
Thespian copied to clipboard

ActorTypeDispatcher Handler Strangeness

Open kevincolyar opened this issue 1 year ago • 2 comments

I've been using Thespian for quite a while now and this is the first time I've had to run down an issue like this.

I have a ActorTypeDispatcher actor with the following methods:


    def receiveMsg_Alert(self, alert, _sender):
        logger.warning(f"Alert message received from {_sender} to save: {alert}")

        self.queue.append(alert)
        self.wakeup()

    # TODO: WHY DOES ADDING THIS MAKE receiveMsg_Alert work above?
    def receiveMsg_dict(self, alert, _sender):
        pass

Where the Alert message type is simply:

class Alert(dict):
    pass

For some reason, messages of the Alert type just would not be handled by the first method until I added the _dict handler. Just by chance I added that method to see if the message type wasn't working, but once I did, it started working.

I have several, almost identical actors that have worked for almost 8 years without issue, but this is the first time I've run into this. Ideas?

kevincolyar avatar Feb 05 '25 21:02 kevincolyar

Is it possible that you had an ActorSystem loaded with an older version of whichever Actor was generating the message (as a dict and not an Alert)? Or are your self.wakeup or self.queue affecting things such that the logging message is not delivered?

The logic for ActorTypeDispatcher https://github.com/thespianpy/Thespian/blob/master/thespian/actors.py#L834-L837 will find the first method in "mro" order, so it should have called receiveMsg_Active first, and since that did not return self.SUPER, there should have been no call to receiveMsg_dict.

kquick avatar Feb 06 '25 13:02 kquick

The odd thing is that receiveMsg_dict is never called. Just the act of having it defined makes receiveMsg_Alert receive messages. If receiveMsg_dict is commented out or removed, receiveMsg_Alert no longer receives messages.

kevincolyar avatar Feb 06 '25 16:02 kevincolyar