Jon
Jon

Reputation: 19

Event when data sent in Twisted Python?

I'm writing a TCP/IP server using the Twisted framework. I am sending a very large stream of data, in small chunks. So I need to know when the data I've sent has made it through Twisted's buffers and into the OS, and the OS is ready for some more data. Is there a way to be notified when this happens?

I am doing this to measure network throughput, so I'm generating an unlimited amount of data.

If I was using normal sockets (not Twisted), the answer would be to use poll() with POLLOUT for that, but I want to do this using Twisted.

Upvotes: 1

Views: 141

Answers (2)

monoid
monoid

Reputation: 1671

There are so called push and pull producers. You need push producer, obviously :)

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

Upvotes: 1

Glyph
Glyph

Reputation: 31860

Yes.

self.transport.registerProducer(AProducer(), True), and then

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"

You can find more in the Twisted documentation for consumers and producers.

Upvotes: 1

Related Questions