[Twisted-Python] Twisted Words: throttling server output

Seventh Holy Scripture 7hs at muchan.org
Sat Dec 3 13:38:14 EST 2005

I've been writing an IRC bot using Twisted Words, and am having  
difficulty keeping it from flooding itself off the server. Currently  
my output subroutines look like this:

     def queueMsg(self, channel, msg):

     def emptyMsgQueue(self):
         for msg in self.msgQueue:
             channel = self.chanQueue.pop(0)
             self.msg(channel, msg)
             if channel[0] == "#":
                 self.logger.log("<%s> %s" % (self.nickname, msg))
         self.msgQueue = []

This ought to work as far as I know... but the bot waits until after  
all the sleep statements have executed to spew the output to the IRC  
server, which (if there's a lot of it) results in a forced disconnect  
due to "Excess Flood". What am I doing wrong here? My guess is that  
twisted has its own message queue, and waits until after all host  
program subroutines have ended to process it... I'm not good at  
python, though, so it could be a stupid mistake on my part.

In any case, is there another way to introduce a delay between the  
messages sent to server that will work?

More information about the Twisted-Python mailing list