Просмотр исходного кода

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 лет назад
Родитель
Сommit
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 = []
task_threads = []
task_thread_num = 0
for thread in threads:
tname = thread.name
@@ -62,25 +61,31 @@ class Tasks(BaseCommand):
elif tname in ["irc-frontend", "irc-watcher", "wiki-scheduler"]:
normal_threads.append("\x0302{}\x0301 (id {})".format(tname, thread.ident))
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:
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:
msg = "\x02{}\x0F threads active: {}, and \x020\x0F task threads.".format(len(threads), ', '.join(normal_threads))
self.connection.reply(self.data, msg)
def do_listall(self):
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 = []
tasks.sort()

for task in tasks:
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:
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)
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.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.start()



Загрузка…
Отмена
Сохранить