每个戏剧演员都在一个线程上运行吗?

发布于 2025-01-17 10:28:15 字数 538 浏览 2 评论 0原文

我在thespian实施中遇到了障碍。我有一个无限的循环,如果满足条件,它将破裂,但我想保持在段环上,直到满足条件。我知道它正在阻止,我很好,在无限循环中无法接收任何消息,但是,直到上一个演员退出他们的无限循环之前,其他演员似乎才进入循环。这使我相信所有演员都在一个线程上。在解决方案上有什么想法吗?

class Actor(ActorTypeDispatcher):
    def logic(self):
        should_break = False
        while True:
            print(self.id)
            if should_break:
                break
            **insert logic to determine if should_break is True or False**

我已经实例化了100个演员(ID从1-100增加)。演员1-5立即在迭代后输入中断语句,但是当我打印ID时,它被卡在6中。打破演员循环的逻辑,其中ID = 6同时取决于其他演员行动。

I am hitting a roadblock in my thespian implementation. I have an infinite while loop that will break if a condition is met, but I want to stay in the while loop until the condition is met. I understand that it is blocking and I am fine with not being able to receive any messages while in the infinite loop, however, it seems like other actors are not entering the loop until the previous actor has exited their infinite loop. This makes me believe that all actors are on a single thread. Any idea on workarounds?

class Actor(ActorTypeDispatcher):
    def logic(self):
        should_break = False
        while True:
            print(self.id)
            if should_break:
                break
            **insert logic to determine if should_break is True or False**

I have instantiated 100 actors (the id is incremented from 1-100). Actors 1-5 immediately enter the break statement after an iteration, however when I print the id it is stuck on 6. The logic to break the loop for Actor where id = 6 is dependent on other Actors actions simultaneously.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红玫瑰 2025-01-24 10:28:15

per thespian docs ::

默认情况下,使用了“ simplesystembase”,它在当前过程中同步运行所有参与者。虽然此基础对于调试非常有用(请参阅调试部分),但它不提供通常在生产时所需的并发水平。

这表明默认情况下,thespian可以有效地在同一线程中运行所有演员。

替代基础(例如Multiproctcpbase,除非您确定要MultiprocudpbaseMultiprocqueuebase)可以选择其他地方作为选择的基础。在启动时传递到actorsystem。默认的siglystembase没有并行性。

Per Thespian's docs:

By default, the "simpleSystemBase" is used, which runs all Actors synchronously in the current process. While this base is very useful for debugging (see the Debugging section), it does not provide the level of concurrency usually desired at production time.

Which suggests that by default Thespian effectively runs all actors in the same thread.

Alternative bases (e.g. the multiprocTCPBase, which the docs elsewhere cite as the base to choose unless you're sure you want multiprocUDPBase or multiprocQueueBase) can be passed to the ActorSystem at startup. The default simpleSystemBase has no parallelism.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文