| |
- __builtin__.object
-
- Pump
- ReadStream
- WriteStream
class Pump(__builtin__.object) |
|
Pumps data from a ReadStream to a WriteStream and performs flow control where necessary to
prevent the write stream from getting overloaded.
Instances of this class read bytes from a ReadStream and write them to a WriteStream. If data
can be read faster than it can be written this could result in the write queue of the WriteStream growing
without bound, eventually causing it to exhaust all available RAM.
To prevent this, after each write, instances of this class check whether the write queue of the WriteStream
is full, and if so, the ReadStream is paused, and a WriteStreamdrain_handler is set on the WriteStream.
When the WriteStream has processed half of its backlog, the drain_handler will be called,
which results in the pump resuming the ReadStream.
This class can be used to pump from any ReadStream to any WriteStream,
e.g. from an HttpServerRequest to an AsyncFile, or from NetSocket to a WebSocket. |
|
Methods defined here:
- __init__(self, read_stream, write_stream)
- set_write_queue_max_size(self, val)
- Set the write queue max size
Keyword arguments:
@param val: The write queue max size
- start(self)
- Start the Pump. The Pump can be started and stopped multiple times.
- stop(self)
- Stop the Pump. The Pump can be started and stopped multiple times.
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
- bytes_pumped
- return the total number of bytes pumped by this pump.
- write_queue_max_size
|
class ReadStream(__builtin__.object) |
|
A mixin module which represents a stream of data that can be read from.
Any class that mixes in this module can be used by a to pump data from a to it. |
|
Methods defined here:
- data_handler(self, handler)
- Set a data handler. As data is read, the handler will be called with the data.
Keyword arguments:
@param handler: The data handler
- end_handler(self, handler)
- Set an end handler on the stream. Once the stream has ended, and there is no more data to be read, this handler will be called.
Keyword arguments:
@param handler: The exception handler
- exception_handler(self, handler)
- Set an execption handler on the stream.
param [Block] hndlr. The exception handler
- pause(self)
- Pause the ReadStream. After calling this, the ReadStream will aim to send no more data to the
- resume(self)
- Resume reading. If the ReadStream has been paused, reading will recommence on it.
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class WriteStream(__builtin__.object) |
|
A mixin module which represents a stream of data that can be written to.
Any class that mixes in this module can be used by a to pump data from a to it. |
|
Methods defined here:
- drain_handler(self, handler)
- Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write
queue has been reduced to maxSize / 2. See for an example of this being used.
Keyword arguments:
@param handler: The drain handler
- exception_handler(self, handler)
- Set an execption handler on the stream.
Keyword arguments:
@param handler: The exception handler
- set_write_queue_max_size(self, size)
- Set the maximum size of the write queue. You will still be able to write to the stream even
if there is more data than this in the write queue. This is used as an indicator by classes such as
to provide flow control.
Keyword arguments:
@param size: The maximum size, in bytes.
- write_buffer(self, buff)
- Write some data to the stream. The data is put on an internal write queue, and the write actually happens
asynchronously. To avoid running out of memory by putting too much on the write queue,
check the method before writing. This is done automatically if using a .
param [Buffer]. The buffer to write.
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
- write_queue_full
- Is the write queue full?
return True if there are more bytes in the write queue than the max write queue size.
- write_queue_max_size
| |