知识卡片
邮箱任务须定义启动停止协议
Actor持有邮箱,send入队,run取消息;close发送终止哨兵,join等任务退出事件。
结构图:
classDiagram
class Actor {
+send(msg)
+recv()
+close()
+start()
+join()
+run()
+_bootstrap()
}
Actor <|-- PrintActor
Actor --> Queue : _mailbox
Actor --> Event : _terminated
继承与持有不同。原join在start前无终止事件,重复start、close后继续send等均未定义;后台daemon不保证退出时所有消息已处理。哨兵终止不替代失败报告或任务取消。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- · 查看原书依据
class Actor: def __init__(self): self._mailbox = Queue() def send(self, msg): ''' Send a message to the actor ''' self._mailbox.put(msg
参考来源
- 位置:《Python Cookbook(第3版)中文版》12.10 定义一个Actor任务(spine20;extracted/Python Cookbook(第3版)中文版/_epub-src/OEBPS/Text/part0018.xhtml;u219-ch12-030)。
- 结论依据:完整读取本条问题、方案、代码与讨论;结论按真实控制流和适用前提表达,额外边界明确为解释或推导,示例未执行。
- 原始内容:class Actor: def __init__(self): self._mailbox = Queue() def send(self, msg): ''' Send a message to the actor ''' self._mailbox.put(msg