diff --git a/plugins/String/plugin.py b/plugins/String/plugin.py index 2aa58c222..72143f72e 100644 --- a/plugins/String/plugin.py +++ b/plugins/String/plugin.py @@ -33,12 +33,14 @@ import binascii import supybot.utils as utils from supybot.commands import * +import supybot.commands as commands import supybot.plugins as plugins import supybot.ircutils as ircutils import supybot.callbacks as callbacks from supybot.i18n import PluginInternationalization, internationalizeDocstring _ = PluginInternationalization('String') +import multiprocessing class String(callbacks.Plugin): @internationalizeDocstring diff --git a/src/callbacks.py b/src/callbacks.py index 3a2eb7fe0..7944981c5 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -988,6 +988,23 @@ class CommandThread(world.SupyThread): finally: self.cb.threaded = self.originalThreaded +class CommandProcess(world.SupyProcess): + """Just does some extra logging and error-recovery for commands that need + to run in processes. + """ + def __init__(self, target=None, args=(), kwargs={}): + self.command = args[0] + self.cb = target.im_self + procName = 'Process #%s (for %s.%s)' % (world.processesSpawned, + self.cb.name(), + self.command) + log.debug('Spawning process %s (args: %r)', procName, args) + self.__parent = super(CommandProcess, self) + self.__parent.__init__(target=target, name=procName, + args=args, kwargs=kwargs) + + def run(self): + self.__parent.run() class CanonicalString(registry.NormalizedString): def normalize(self, s): diff --git a/src/commands.py b/src/commands.py index 4c26e29a6..82b5b2280 100644 --- a/src/commands.py +++ b/src/commands.py @@ -37,6 +37,8 @@ import types import getopt import inspect import threading +import multiprocessing #python2.6 or later! +import Queue import supybot.log as log import supybot.conf as conf diff --git a/src/version.py b/src/version.py index 8b46f4516..7f6f5aceb 100644 --- a/src/version.py +++ b/src/version.py @@ -1,3 +1,3 @@ """stick the various versioning attributes in here, so we only have to change them once.""" -version = '0.83.4.1+limnoria (2011-08-13T01:59:18+0200)' +version = '0.83.4.1+limnoria (2011-08-15T17:24:33+0200)' diff --git a/src/world.py b/src/world.py index 23ec3789e..c69d37a7a 100644 --- a/src/world.py +++ b/src/world.py @@ -37,6 +37,7 @@ import sys import time import atexit import threading +import multiprocessing # python 2.6 and later! if sys.version_info >= (2, 5, 0): import re as sre @@ -67,6 +68,15 @@ class SupyThread(threading.Thread): super(SupyThread, self).__init__(*args, **kwargs) log.debug('Spawning thread %q.', self.getName()) +processesSpawned = 1 # Starts at one for the initial process. +class SupyProcess(multiprocessing.Process): + def __init__(self, *args, **kwargs): + global processesSpawned + processesSpawned += 1 + super(SupyProcess, self).__init__(*args, **kwargs) + log.debug('Spawning process %q.', self.name) + + commandsProcessed = 0 ircs = [] # A list of all the IRCs.