[Twisted-Python] IPushProducer problem

Gabriel Rossetti gabriel.rossetti at arimaz.com
Tue Jan 13 08:34:29 MST 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 : 
http://www.twistedmatrix.com/pipermail/twisted-python/2007-March/014983.html

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.transport.write(data)
            self.__startLimit = self.__endLimit
            self.__endLimit += self.__burstSize
            if(not self.__stream):
                break

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

    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)
        if(self.__stream):
            self.resumeProducing()

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,
Gabriel




More information about the Twisted-Python mailing list