gavo.svcs.streaming module

Streaming out large computed things using twisted and threads.

class gavo.svcs.streaming.DataStreamer(writeStreamTo, consumer, queryMeta=None)[source]

Bases: threading.Thread

is a twisted-enabled Thread to stream out large files produced on the fly.

It is basically a push producer. To use it, construct it with a data source and a twisted request (or any IFinishableConsumer) If in a twisted resource, you should arrange a deferred and return NOT_DONE_YET; really, just use streamOut below.

The data source simply is a function writeStreamTo taking one argument, which is file-like (i.e., use its write method to deliver data). There’s no need to close anything, just let your function return.

writeStream will be run in a thread to avoid blocking the reactor.


Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

synchronized = ['resumeProducing', 'pauseProducing', 'stopProducing']

schedules data to be written to the consumer.

exception gavo.svcs.streaming.StopWriting[source]

Bases: OSError

clients can raise this when they want the stream to abort.

gavo.svcs.streaming.streamOut(writeStreamTo, request, queryMeta=None)[source]

sets up the thread to have writeStreamTo write to request from a thread.

For convenience, this function returns server.NOT_DONE_YET, so in a t.w render method you can just say return streamOut().

We manage all necessary callbacks and errback ourselves.

gavo.svcs.streaming.streamVOTable(request, data, queryMeta=None, **contextOpts)[source]

streams out the payload of a data item as a VOTable.