Go to the latest version of this document.

# ``twisted`.`internet`.`abstract`.`_ConsumerMixin``

class documentation

`class _ConsumerMixin: (source)`

Known subclasses: `twisted.internet.abstract.FileDescriptor`, `twisted.internet.iocpreactor.abstract.FileHandle`

View In Hierarchy

`IConsumer` implementations can mix this in to get `registerProducer` and `unregisterProducer` methods which take care of keeping track of a producer's state.

Subclasses must provide three attributes which `_ConsumerMixin` will read but not write:

- connected: A `bool` which is `True` as long as the consumer has someplace to send bytes (for example, a TCP connection), and then `False` when it no longer does.
- disconnecting: A `bool` which is `False` until something like `ITransport.loseConnection` is called, indicating that the send buffer should be flushed and the connection lost afterwards. Afterwards, `True`.
- disconnected: A `bool` which is `False` until the consumer no longer has a place to send bytes, then `True`.

Subclasses must also override the `startWriting` method.

Method | `registerProducer` | Register to receive data from a producer.
Method | `startWriting` | Override in a subclass to cause the reactor to monitor this selectable for write events. This will be called once in `unregisterProducer` if `loseConnection` has previously been called, so that the connection can actually close.
Method | `unregisterProducer` | Stop consuming data from a producer, without disconnecting.
Instance Variable | `producer` | `None` if no producer is registered, otherwise the registered producer.
Instance Variable | `producerPaused` | A flag indicating whether the producer is currently paused.
Instance Variable | `streamingProducer` | `bool` or `int`

def registerProducer(self, producer, streaming): (source)
overridden in `twisted.internet.iocpreactor.tcp.Connection`

Register to receive data from a producer.

This sets this selectable to be a consumer for a producer. When this selectable runs out of data on a write() call, it will ask the producer to resumeProducing(). When the FileDescriptor's internal data buffer is filled, it will ask the producer to pauseProducing(). If the connection is lost, FileDescriptor calls producer's stopProducing() method.

If streaming is true, the producer should provide the IPushProducer interface. Otherwise, it is assumed that producer provides the IPullProducer interface. In this case, the producer won't be asked to pauseProducing(), but it has to be careful to write() data only when its resumeProducing() method is called.

def startWriting(self): (source)
overridden in `twisted.internet.abstract.FileDescriptor`, `twisted.internet.iocpreactor.abstract.FileHandle`

Override in a subclass to cause the reactor to monitor this selectable for write events. This will be called once in `unregisterProducer` if `loseConnection` has previously been called, so that the connection can actually close.

def unregisterProducer(self): (source)
overridden in `twisted.internet.iocpreactor.tcp.Connection`

Stop consuming data from a producer, without disconnecting.

producer = (source)
overridden in `twisted.internet.abstract.FileDescriptor`, `twisted.internet.iocpreactor.abstract.FileHandle`

`None` if no producer is registered, otherwise the registered producer.

producerPaused: `bool` = (source)
overridden in `twisted.internet.abstract.FileDescriptor`, `twisted.internet.iocpreactor.abstract.FileHandle`

A flag indicating whether the producer is currently paused.

streamingProducer: `bool` = (source)

`bool` or `int`