How to make Python Thespian Actor framework work with nested Actors?

353 views Asked by At

I am trying to run a very simple example using Thespian Actors in witch one actor lauches another.

from thespian.actors import *
import logging

logging.basicConfig(level=logging.DEBUG)

class serviceA(Actor):
    def __init__(self):
        logging.info(f"{str(self.__class__)} loaded")
    def receiveMessage(self, message, sender):
            logging.info(f"message received: {message}")
            if (message == 'create another'):
                logging.info("creating another...")
                newActor = self.createActor(serviceB)

class serviceB(Actor):
    def __init__(self):
        logging.info(f"{str(self.__class__)} loaded")

def run():
    ActorSystem() 
    A = ActorSystem().createActor(serviceA)
    ActorSystem().tell(A,'create another')

    input()
    ActorSystem().shutdown()

if __name__ == "__main__":
    run()

When I start with an ActorSystem("simpleSystemBase") it works well, and I get this:

2023-02-23 15:07:39,913 INFO    =>  <class '__main__.serviceA'> loaded  [teste_nestedActors.py:9]
2023-02-23 15:07:39,913 INFO    =>  message received: create another  [teste_nestedActors.py:11]
2023-02-23 15:07:39,913 INFO    =>  creating another...  [teste_nestedActors.py:13]
2023-02-23 15:07:39,913 INFO    =>  <class '__main__.serviceB'> loaded  [teste_nestedActors.py:18]

However, if I use any other systemBase, it doesn't work.

For ActorSystem("multiprocQueueBase") I get:

INFO:root:++++ Actor System gen (3, 10) started, admin @ ActorAddr-Q.ThespianQ
DEBUG:root:Thespian source: C:\Users\tomaz\AppData\Local\Programs\Python\Python310\lib\site-packages\thespian\__init__.py

and for TCP or UDP I get this error:

raise InvalidActorAddress(self.adminAddr,    thespian.actors.InvalidActorAddress: ActorAddr-(T|:1900) is not a valid or useable ActorSystem Admin

Any tips?

I wanted an Actor to create another using multiprocessing systemBase's, but I only managed to do so without parallelism, using the simpleSystemBase.

Thanks, André.

1

There are 1 answers

2
KQ. On

if you get this "is not a valid or useable ActorSystem Admin" error that means it is not able to start the "admin" actor at well-known port 1900. This "admin" actor coordinates the activities of the actors on this system, and also handle connections between local actors and actors on other systems.

You might try something like $ netstat -vanep | grep 1900 to see if you already have something else running on that port. If you do, you can either stop that other service, or direct Thespian to use a different admin port (see the "Admin Port" setting at https://thespianpy.com/doc/using.html#hH-9d33a877-b4f0-4012-9510-442d81b0837c.

There's not enough output from your multiprocQueueBase to determine what the problem was there; perhaps a previous ActorSystem of a different base was already started in that process, but that's purely a guess.

If you return to using Thespian, I'm happy to help resolve issues either here or via the Thespian issues reporting (sorry for the delay, I was travelling out of the country).

-Kevin [Thespian author]