【问题标题】:Pykka: How to cancel an actor's pending messages queue when it has been stoppedPykka:如何在参与者停止时取消参与者的待处理消息队列
【发布时间】:2015-03-22 17:07:54
【问题描述】:

我玩过 Pykka 演员库,我想出了以下真棒愚蠢的例子:

import pykka
from time import sleep

class TestActor(pykka.ThreadingActor):
    def on_receive(self, message):
        sleep(1)
        print(message["v"])    

a = TestActor.start()
for i in xrange(10):
    print("asking for " + str(i))
    a.tell({"v":i})
print(a.stop())

我得到了预期的结果:10 请求 行立即打印,另外 10 行每行在 1 秒内打印:

asking for 0
asking for 1
asking for 2
asking for 3
asking for 4
asking for 5
asking for 6
asking for 7
asking for 8
asking for 9
0
1
2
3
4
5
6
7
8
9
True

演员处理完所有请求后,True 将作为 stop 操作的结果打印出来。

我想知道是否可以停止演员从而取消接收和处理重复消息。

I've checked the library documentation 但我能找到的只是block 停止参数,这意味着完全不同的事情:当设置为False 时,它使调用是异步的,但它关于消息队列的行为是相同的:

stop(block=True, timeout=None)

向actor发送消息,询问它 停下来。

如果 actor 已停止或正在停止,则返回 True 通话。如果演员已经死了,则为假。如果块为假,它 返回包装结果的未来。

在要求演员停止之前发送给演员的消息将是 在停止之前正常处理。

演员被要求停止后发送给演员的消息将是 停止后用 pykka.ActorDeadError 回复。

actor 可能不会重新启动。

block 和 timeout 与 ask() 一样。

返回:pykka.Future,如果阻塞则返回布尔值

【问题讨论】:

    标签: python concurrency actor pykka


    【解决方案1】:

    Pykka 当前 (1.2.0) 不支持中断消息队列。

    来源:https://github.com/jodal/pykka/issues/46

    【讨论】:

      猜你喜欢
      • 2023-03-18
      • 1970-01-01
      • 2011-03-24
      • 1970-01-01
      • 2017-07-31
      • 2013-08-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-09
      相关资源
      最近更新 更多