diff --git a/plugins/String/plugin.py b/plugins/String/plugin.py index b836cbb1f..6127e2755 100644 --- a/plugins/String/plugin.py +++ b/plugins/String/plugin.py @@ -138,7 +138,7 @@ class String(callbacks.Plugin): s = 'You probably don\'t want to match the empty string.' irc.error(s) else: - v = commands.process(f, text, timeout=10) + v = commands.process(f, text, timeout=10, pn=self.name(), cn='re') irc.reply(v) re = thread(wrap(re, [first('regexpMatcher', 'regexpReplacer'), 'text'])) diff --git a/src/callbacks.py b/src/callbacks.py index 822e06616..4d9396708 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -981,11 +981,11 @@ class CommandProcess(world.SupyProcess): to run in processes. """ def __init__(self, target=None, args=(), kwargs={}): - self.command = args[0] - self.cb = target.im_self + pn = kwargs.pop('pn', 'Unknown') + cn = kwargs.pop('cn', 'unknown') procName = 'Process #%s (for %s.%s)' % (world.processesSpawned, - self.cb.name(), - self.command) + pn, + cn) log.debug('Spawning process %s (args: %r)', procName, args) self.__parent = super(CommandProcess, self) self.__parent.__init__(target=target, name=procName, diff --git a/src/commands.py b/src/commands.py index 1879082c2..8b1994faf 100644 --- a/src/commands.py +++ b/src/commands.py @@ -70,22 +70,27 @@ def thread(f): return utils.python.changeFunctionName(newf, f.func_name, f.__doc__) def process(f, *args, **kwargs): - """Runs a function in a subprocess. - Takes an extra timeout argument, which, if supplied, limits the length - of execution of target function to seconds.""" - timeout = kwargs.pop('timeout') + """Runs a function in a subprocess. + + Several extra keyword arguments can be supplied. + , the pluginname, and , the command name, are strings used to + create the process name, for identification purposes. + , if supplied, limits the length of execution of target + function to seconds.""" + timeout = kwargs.pop('timeout', None) + q = multiprocessing.Queue() def newf(f, q, *args, **kwargs): r = f(*args, **kwargs) q.put(r) targetArgs = (f, q,) + args - p = world.SupyProcess(target=newf, + p = callbacks.CommandProcess(target=newf, args=targetArgs, kwargs=kwargs) p.start() p.join(timeout) if p.is_alive(): p.terminate() - q.put("Function call aborted due to timeout.") + q.put("%s aborted due to timeout." % (p.name,)) try: v = q.get(block=False) except Queue.Empty: