[Twisted-Python] pcp.ProducerConsumerProxy.resumeProducing

Eric C. Newton ecn at metaslash.com
Thu May 8 21:56:45 EDT 2003


Linux RedHat 9.0
Twisted 1.0.4

In method resumeProducing of pcp.ProducerConsumerProxy, there's this
code:

        if self.producer is not None:
            bytesBuffered = reduce(operator.add,
                                   [len(s) for s in self._buffer], 0)
            # TODO: You can see here the potential for high and low
            # watermarks, where bufferSize would be the high mark when we
            # ask the upstream producer to pause, and we wouldn't have
            # it resume again until it hit the low mark.  Or if producer
            # is Pull, maybe we'd like to pull from it as much as necessary
            # to keep our buffer full to the low mark, so we're never caught
            # without something to send.
            if self.producerPaused and (bytesBuffered < self.bufferSize):
                # Now that our buffer is empty,
                self.producerPaused = False
                self.producer.resumeProducing()
            elif self.outstandingPull:
                # I did not have any data to write in response to a pull,
                # so I'd better pull some myself.
                self.producer.resumeProducing()

At the condition:

            elif self.outstandingPull:

It's possible that the producer is sending data in big chunks, and we
are only writing them out in little chunks.  If so, we continue to add
bytes to the buffer and disregard the buffer limit.  I've changed the
line to this:

            elif self.outstandingPull and (bytesBuffered < self.bufferSize):

and all is well.  Except maybe the code should be refactored (without
comments now):

	    if bytesBuffered < self.bufferSize:
		if self.producerPaused or self.outstandingPull:
		    self.producer.resumeProducing()
		self.producerPaused = False

-Eric




More information about the Twisted-Python mailing list