如何让Python Thespian Actor框架与嵌套的演员一起工作?

huangapple go评论59阅读模式
英文:

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

问题

我正在尝试运行一个使用Thespian Actors的非常简单的示例,其中一个actor启动另一个。

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()

当我使用ActorSystem("simpleSystemBase")启动时,它运行良好,并且我得到这个:

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]

然而,如果我使用任何其他systemBase,它不起作用。

对于ActorSystem("multiprocQueueBase"),我得到:

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

对于TCP或UDP,我得到这个错误:

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

有什么建议吗?

我想要一个Actor使用multiprocessing systemBase创建另一个,但我只能在没有并行性的情况下使用simpleSystemBase成功实现。

英文:

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&quot;{str(self.__class__)} loaded&quot;)
    def receiveMessage(self, message, sender):
            logging.info(f&quot;message received: {message}&quot;)
            if (message == &#39;create another&#39;):
                logging.info(&quot;creating another...&quot;)
                newActor = self.createActor(serviceB)

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

def run():
    ActorSystem() 
    A = ActorSystem().createActor(serviceA)
    ActorSystem().tell(A,&#39;create another&#39;)

    input()
    ActorSystem().shutdown()

if __name__ == &quot;__main__&quot;:
    run()

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

2023-02-23 15:07:39,913 INFO    =&gt;  &lt;class &#39;__main__.serviceA&#39;&gt; loaded  [teste_nestedActors.py:9]
2023-02-23 15:07:39,913 INFO    =&gt;  message received: create another  [teste_nestedActors.py:11]
2023-02-23 15:07:39,913 INFO    =&gt;  creating another...  [teste_nestedActors.py:13]
2023-02-23 15:07:39,913 INFO    =&gt;  &lt;class &#39;__main__.serviceB&#39;&gt; 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

得分: 2

如果你收到这个错误消息 "is not a valid or useable ActorSystem Admin",那意味着它无法在众所周知的端口1900上启动 "admin" actor。这个 "admin" actor 协调系统上的各个actor的活动,并处理本地actor与其他系统上的actor之间的连接。

你可以尝试运行类似 $ netstat -vanep | grep 1900 的命令,以查看是否已经有其他东西在该端口上运行。如果有,你可以停止那个其他服务,或者指示 Thespian 使用不同的管理端口(参见 https://thespianpy.com/doc/using.html#hH-9d33a877-b4f0-4012-9510-442d81b0837c 中的 "Admin Port" 设置)。

从你的 multiprocQueueBase 输出来看,无法确定问题的具体原因;也许在该进程中已经启动了一个不同基础的之前的 ActorSystem,但这只是一个猜测。

如果你决定继续使用 Thespian,我愿意在这里或通过 Thespian 的问题报告方式协助解决问题(对于延迟,我当时正在出国旅行,抱歉)。

-Kevin [Thespian 作者]

英文:

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]

huangapple
  • 本文由 发表于 2023年2月24日 02:26:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75548872.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定