From 07ce4a38f20bb04d0e046e3bfd63d2345730b28f Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sat, 14 May 2011 14:27:23 -0400 Subject: [PATCH] message cleanup --- irc/commands/tasks.py | 13 ++++--------- wiki/task_manager.py | 2 +- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/irc/commands/tasks.py b/irc/commands/tasks.py index 6c2c83a..a1f6033 100644 --- a/irc/commands/tasks.py +++ b/irc/commands/tasks.py @@ -62,7 +62,7 @@ class Tasks(BaseCommand): normal_threads.append("\x0302{}\x0301 (id {})".format(tname, thread.ident)) else: tname, start_time = re.findall("^(.*?) \((.*?)\)$", tname)[0] - task_threads.append("\x0302{}\x0301 (id {}, spawned at {})".format(tname, thread.ident, start_time)) + task_threads.append("\x0302{}\x0301 (id {}, since {})".format(tname, thread.ident, start_time)) if task_threads: msg = "\x02{}\x0F threads active: {}, and \x02{}\x0F task threads: {}.".format(len(threads), ', '.join(normal_threads), len(task_threads), ', '.join(task_threads)) @@ -72,8 +72,7 @@ class Tasks(BaseCommand): def do_listall(self): tasks = task_manager.task_list.keys() - threadlist = threading.enumerate() - threads = map(lambda t: t.name, threadlist) + threads = threading.enumerate() tasklist = [] tasks.sort() @@ -112,12 +111,8 @@ class Tasks(BaseCommand): self.connection.reply(data, "task could not be found; either wiki/tasks/{}.py doesn't exist, or it wasn't loaded correctly.".format(task_name)) return - if data.kwargs: - task_manager.start_task(task_name, **data.kwargs) - self.connection.reply(data, "task \x0302{}\x0301 started with arguments: {}.".format(task_name, data.kwargs)) - else: - task_manager.start_task(task_name) - self.connection.reply(data, "task \x0302{}\x0301 started.".format(task_name)) + task_manager.start_task(task_name, **data.kwargs) + self.connection.reply(data, "task \x0302{}\x0301 started.".format(task_name)) def get_main_thread_name(self): """Return the "proper" name of the MainThread; e.g. "irc-frontend" or "irc-watcher".""" diff --git a/wiki/task_manager.py b/wiki/task_manager.py index cd3b79b..b17cbbb 100644 --- a/wiki/task_manager.py +++ b/wiki/task_manager.py @@ -64,7 +64,7 @@ def start_task(task_name, **kwargs): return task_thread = threading.Thread(target=lambda: task_wrapper(task, **kwargs)) # Normally we'd do task_wrapper(task, **kwargs), but because of threading we'd have to do Thread(target=task_wrapper, args=(task, **kwargs)), which doesn't work because the **kwargs is inside a tuple, not inside function params. Use lambda to get around the args=tuple nonsense - task_thread.name = "{} ({} UTC)".format(task_name, time.asctime()) + task_thread.name = "{} ({})".format(task_name, time.strftime("%b %d %H:%M:%S")) task_thread.daemon = True # stop bot task threads automagically if the main bot stops task_thread.start()