知识卡片

结构图卡 · 8025.gk · 生成模型:未记录

进程输出分块不是业务消息边界

理解等级:中级

CommandSlot用队列把请求对应到子进程结果,但outReceived得到的是任意字节块,可能半行、多行或含其他输出。直接pop一个Deferred再float(data)不构成可靠逐行协议;需要缓冲、分帧和明确结果对应,Python3 transport.write也应按字节契约编码。Pricing是Item管道而非原文称的爬虫。本次没有派生进程。

结构图: 类图

classDiagram
 class ProcessProtocol
 class CommandSlot {
  -_queue
  +legacy_calculate(price) Deferred
  +outReceived(data)
 }
 class Pricing {
  -slots
  -rr
  +process_item(item, spider)
 }
 ProcessProtocol <|-- CommandSlot
 Pricing o-- CommandSlot : 单实例或轮询池
 CommandSlot --> ProcessTransport : stdin与stdout
 note for CommandSlot "精简例缺分帧/退出失败结清;图不表示已可靠实现"
这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Python编程精进(第1辑)(套装共3册)(异步图书)》精通Python爬虫框架Scrapy · 第9章 管道秘诀,spine041单元014;来源项目book-sources,extracted/Python编程精进(第1辑)(套装共3册)(异步图书)/_epub-src/OEBPS/text00040.html。 - 结论依据:原文outReceived直接pop等待者并float(data),未做缓冲分帧,按接口字节块可拆合消息,故不能证明一块输出恰对应一条结果。补充核验入口:https://docs.twisted.org/en/stable/core/howto/process.html。未在本机运行示例或改变环境。 - 原始内容:用该脚本呢?仍然从一个简化的版本起步。 class CommandSlot(protocol.ProcessProtocol): def __init__(self, args): self._queue = [] reactor.spawnProcess(self, args[0], args