[Twisted-Python] Twisted Words: throttling server output

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): self.chanQueue.append(channel) self.msgQueue.append(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)) time.sleep(0.5) 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?

On Sat, 3 Dec 2005 10:38:14 -0800, Seventh Holy Scripture <7hs@muchan.org> wrote:
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): self.chanQueue.append(channel) self.msgQueue.append(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)) time.sleep(0.5) self.msgQueue = []
The time.sleep() call blocks the entire reactor thread. Eventually, the loop exits, the reactor regains control of program flow, notices a huge pile of messages in the IRC connection's output buffer, and sends them all as fast as it can. Woops. :) Take a look at reactor.callLater() or twisted.internet.task.LoopingCall(). These will let you schedule events to happen at particular times without blocking the reactor, and thus allowing each message to be sent at a reasonable time. Jean-Paul

Seventh Holy Scripture <7hs@muchan.org> writes:
In any case, is there another way to introduce a delay between the messages sent to server that will work?
Are you aware of the 'lineRate' variable on irc.IRCClient? Cheers, mwh -- I have a feeling that any simple problem can be made arbitrarily difficult by imposing a suitably heavy administrative process around the development. -- Joe Armstrong, comp.lang.functional
participants (3)
-
Jean-Paul Calderone
-
Michael Hudson
-
Seventh Holy Scripture