I'm making an IRC bot that works primarily on a plugin system. Every plugin has aparse()
method that will get called when the bot is pinged (I.E. receives an IRC message with its own name in it). Right now I am iterating through the each parse()
method like so for every message received that is pinging the bot:
# only trigger if message is pinging bot
if message.split()[0].find(self.config['botnick']) != -1:
message = self.format_message(message)
for plugin in self.plugins.
plugin.parse(nick, channel, message)
Now, a few of these plugins can take some time to run, anywhere from 10-60 seconds. During this time, the bot in unresponsive because it is handling another task, and once that task is done it will receive any "buffered" messages and act accordingly. If there are multiple pings to this bot, obviously this can cause backup.
So my question is this: how should I go about properly threading this? Should I fork each message out to a new thread, or make a new thread for each plugin once it's verified that the message is pinging the bot? The end goal here is to be able to have the bot respond to additional pings while it is performing some tasks for a previous ping.