【问题标题】:Event when data sent in Twisted Python?以 Twisted Python 发送数据时的事件?
【发布时间】:2015-11-23 17:03:05
【问题描述】:

我正在使用 Twisted 框架编写 TCP/IP 服务器。我正在发送非常大的数据流,小块。所以我需要知道我发送的数据何时通过 Twisted 的缓冲区并进入操作系统,并且操作系统已准备好接收更多数据。有没有办法在发生这种情况时得到通知?

我这样做是为了测量网络吞吐量,因此我会生成无限量的数据。

如果我使用的是普通套接字(不是 Twisted),答案是使用 poll() 和 POLLOUT,但我想使用 Twisted。

【问题讨论】:

    标签: python twisted twisted.internet


    【解决方案1】:

    是的。

    self.transport.registerProducer(AProducer(), True),然后

    from zope.interface import implementer
    from twisted.internet.interfaces import IPushProducer
    @implementer(IPushProducer)
    class AProducer:
        def pauseProducing(self):
            "stop producing data; buffers are full"
        def resumeProducing(self):
            "resume producing data; buffers have space"
    

    您可以在the Twisted documentation for consumers and producers 中找到更多信息。

    【讨论】:

      【解决方案2】:

      有所谓的推拉生产者。显然,您需要推送生产者:)

      http://twistedmatrix.com/documents/13.1.0/core/howto/producers.html

      【讨论】:

        猜你喜欢
        • 2010-11-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多