Prev | Index | Next

Sample Pull Producer

class FileProducer:

    def __init__(self, file, size, transport):
        self.file = file; self.size = size
        self.transport = transport
        transport.registerProducer(self, 0)
    def resumeProducing(self):
        data = self.file.read(10000)
        self.transport.write(data)
        if self.file.tell() == self.size:
            self.transport.unregisterProducer()
    def stopProducing(self):
        self.file.close()