From 03647ce53d94b0dd96eff63a3cd593ae7cf83767 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Tue, 20 Jan 2004 22:09:10 +0000 Subject: [PATCH] Added supybot.threadAllCommands. --- src/callbacks.py | 14 +++++++++++--- src/conf.py | 7 +++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/callbacks.py b/src/callbacks.py index 2cb2808ec..075ab6f2c 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -474,7 +474,7 @@ class IrcObjectProxy(RichReplyMethods): return command = getattr(cb, name) Privmsg.handled = True - if cb.threaded: + if cb.threaded or conf.supybot.threadAllCommands(): t = CommandThread(target=self._callCommand, args=(name, command, cb)) t.start() @@ -595,14 +595,22 @@ class CommandThread(threading.Thread): to run in threads. """ def __init__(self, target=None, args=None): - (name, command, cb) = args + (self.name, self.command, self.cb) = args world.threadsSpawned += 1 threadName = 'Thread #%s for %s.%s' % (world.threadsSpawned, - cb.name(), name) + self.cb.name(), self.name) log.debug('Spawning thread %s' % threadName) threading.Thread.__init__(self, target=target, name=threadName, args=args) self.setDaemon(True) + self.originalThreaded = self.cb.threaded + self.cb.threaded = True + + def run(self): + try: + threading.Thread.run(self) + finally: + self.cb.threaded = self.originalThreaded class ConfigIrcProxy(RichReplyMethods): diff --git a/src/conf.py b/src/conf.py index 42bc60207..74ec9cf00 100644 --- a/src/conf.py +++ b/src/conf.py @@ -149,11 +149,14 @@ number of seconds to throttle snarfed URLs, in order to prevent loops between two bots snarfing the same URLs and having the snarfed URL in the output of the snarf message.""")) +supybot.register('threadAllCommands', registry.Boolean(False, """Determines +whether the bot will automatically thread all commands. At this point this +option exists almost exclusively for debugging purposes; it can do very little +except to take up more CPU.""")) + ### # Reply/error tweaking. ### - -# TODO: These should probably all be channel-specific. supybot.registerGroup('reply') supybot.reply.register('oneToOne', registry.Boolean(True, """Determines whether the bot will send multi-message replies in a single messsage or in multiple