[Twisted-Python] IPushProducer problem

Gabriel Rossetti gabriel.rossetti at arimaz.com
Tue Jan 13 10:34:29 EST 2009

Hello everyone,

I implemented a push-produce a while back and I though it works, but it 
didn't. When the msgs where spaced out, it worked, but if several msgs 
were sent one after the other, then things go bad (the msgs get mixed up)...

I found this thread : 

and I think I ave the same problem, my code looks a bit like his :

    def pauseProducing(self):
        Pause the producer
        self.__paused = True

    def resumeProducing(self):
        Resume the producer
        self.__paused = False

        while(not self.__paused and self.__startLimit < self.__total):
            data = self.__buf[self.__startLimit:self.__endLimit]
            self.__startLimit = self.__endLimit
            self.__endLimit += self.__burstSize
            if(not self.__stream):

        if(not self.__paused or self.__startLimit >= self.__total):

    def stopProducing(self):
        Stop the producer
        self.__paused = False
        self.__startLimit = 0
        self.__buf = None
        self.__total = None
        self.__endLimit = self.__burstSize

and when I send a msg I use this :

def sendMessage(self, msg):
        if domish.IElement.providedBy(msg):
            msg = msg.toXml()
        if isinstance(msg, unicode):
            msg = msg.encode('utf-8')
        self.__buf = msg
        self.__total = len(msg)

I think what happens is that the code is re-entered, just like Jean-Paul 
suggested in the other thread. The thing is I didn't understand the 
solution, could somebody please explain it to me or suggest something else?

Thank you,

More information about the Twisted-Python mailing list