Преглед на файлове

give ids of active tasks with .tasks listall; give start time of threads with .tasks list; fix in task_manager.py

tags/v0.1
Ben Kurtovic преди 13 години
родител
ревизия
ea83a59372
променени са 2 файла, в които са добавени 12 реда и са изтрити 8 реда
  1. +11
    -6
      irc/commands/tasks.py
  2. +1
    -2
      wiki/task_manager.py

+ 11
- 6
irc/commands/tasks.py Целия файл

@@ -52,7 +52,6 @@ class Tasks(BaseCommand):
normal_threads = [] normal_threads = []
task_threads = [] task_threads = []
task_thread_num = 0
for thread in threads: for thread in threads:
tname = thread.name tname = thread.name
@@ -62,25 +61,31 @@ class Tasks(BaseCommand):
elif tname in ["irc-frontend", "irc-watcher", "wiki-scheduler"]: elif tname in ["irc-frontend", "irc-watcher", "wiki-scheduler"]:
normal_threads.append("\x0302{}\x0301 (id {})".format(tname, thread.ident)) normal_threads.append("\x0302{}\x0301 (id {})".format(tname, thread.ident))
else: else:
task_thread_num += 1
task_threads.append("\x0302{}\x0301 (id {})".format(tname, thread.ident))
tname, start_time = re.findall("^(.*?) \((.*?)\)$")[0]
task_threads.append("\x0302{}\x0301 (id {}, spawned at {})".format(tname, thread.ident, start_time))
if task_threads: if task_threads:
msg = "\x02{}\x0F threads active: {}, and \x02{}\x0F task threads: {}.".format(len(threads), ', '.join(normal_threads), task_thread_num, ', '.join(task_threads))
msg = "\x02{}\x0F threads active: {}, and \x02{}\x0F task threads: {}.".format(len(threads), ', '.join(normal_threads), len(task_threads), ', '.join(task_threads))
else: else:
msg = "\x02{}\x0F threads active: {}, and \x020\x0F task threads.".format(len(threads), ', '.join(normal_threads)) msg = "\x02{}\x0F threads active: {}, and \x020\x0F task threads.".format(len(threads), ', '.join(normal_threads))
self.connection.reply(self.data, msg) self.connection.reply(self.data, msg)
def do_listall(self): def do_listall(self):
tasks = task_manager.task_list.keys() tasks = task_manager.task_list.keys()
threads = map(lambda t: t.name, threading.enumerate())
threadlist = threading.enumerate()
threads = map(lambda t: t.name, threadlist)
tasklist = [] tasklist = []
tasks.sort() tasks.sort()


for task in tasks: for task in tasks:
if task in threads: if task in threads:
tasklist.append("\x0302{}\x0301 (\x02active\x0F)".format(task))
threads_running_task = [t for t in threads if t.name.startswith(task)]
ids = map(lambda t: t.ident, threads_running_task)
if len(ids) == 1:
tasklist.append("\x0302{}\x0301 (\x02active\x0F as id {})".format(task, ids[0]))
else:
tasklist.append("\x0302{}\x0301 (\x02active\x0F as ids {})".format(task, ' ,'.join(ids)))
else: else:
tasklist.append("\x0302{}\x0301 (idle)".format(task)) tasklist.append("\x0302{}\x0301 (idle)".format(task))


+ 1
- 2
wiki/task_manager.py Целия файл

@@ -63,9 +63,8 @@ def start_task(task_name, **kwargs):
print "Couldn't find task '{}': wiki/tasks/{}.py does not exist.".format(task_name, task_name) print "Couldn't find task '{}': wiki/tasks/{}.py does not exist.".format(task_name, task_name)
return return
# task_thread = threading.Thread(target=task_wrapper, args=(task, kwargs))
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 = 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 = "task {} (spawned at {} UTC)".format(task_name, time.asctime())
task_thread.name = "{} ({} UTC)".format(task_name, time.asctime())
task_thread.daemon = True # stop bot task threads automagically if the main bot stops task_thread.daemon = True # stop bot task threads automagically if the main bot stops
task_thread.start() task_thread.start()




Зареждане…
Отказ
Запис