簡體   English   中英

在Twisted Python中發送數據時發生事件?

[英]Event when data sent in Twisted Python?

我正在使用Twisted框架編寫TCP / IP服務器。 我正在以小塊發送非常大的數據流。 因此,我需要知道我發送的數據何時通過Twisted的緩沖區傳輸到操作系統中,並且操作系統已准備好接收更多數據。 發生這種情況時,有沒有辦法通知您?

我這樣做是為了測量網絡吞吐量,因此我正在生成無限量的數據。

如果我使用的是普通套接字(而不是Twisted),答案是將poll()與POLLOUT一起使用,但是我想使用Twisted來做到這一點。

是。

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"

您可以在Twisted文檔中為消費者和生產者找到更多信息。

有所謂的推拉生產者。 你需要推生產者,顯然:)

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM