From 69c1bbea5bcf78db5f9f4169186b7b8bdc17b577 Mon Sep 17 00:00:00 2001 From: Dominic Cerquetti Date: Sat, 20 Aug 2016 10:25:53 -0400 Subject: [PATCH 1/2] add override for thread names for DaemonTasks - this is useful to add a more descriptive name to be shown to the OS --- sideboard/lib/_threads.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sideboard/lib/_threads.py b/sideboard/lib/_threads.py index c8b8d37..db1bad6 100644 --- a/sideboard/lib/_threads.py +++ b/sideboard/lib/_threads.py @@ -10,11 +10,13 @@ class DaemonTask(object): - def __init__(self, func, interval=0.1, threads=1): + def __init__(self, func, interval=0.1, threads=1, name=None): self.lock = Lock() self.threads = [] self.stopped = Event() self.func, self.interval, self.thread_count = func, interval, threads + self.name = name if name else self.func.__name__ + on_startup(self.start) on_shutdown(self.stop) @@ -39,7 +41,7 @@ def start(self): del self.threads[:] for i in range(self.thread_count): t = Thread(target = self.run) - t.name = '{}-{}'.format(self.func.__name__, i + 1) + t.name = '{}-{}'.format(self.name, i + 1) t.daemon = True t.start() self.threads.append(t) From f2ead43a762ae443fa32732780e76070c88dcdcb Mon Sep 17 00:00:00 2001 From: Dominic Cerquetti Date: Sun, 21 Aug 2016 16:04:57 -0400 Subject: [PATCH 2/2] style fix --- sideboard/lib/_threads.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sideboard/lib/_threads.py b/sideboard/lib/_threads.py index db1bad6..683545e 100644 --- a/sideboard/lib/_threads.py +++ b/sideboard/lib/_threads.py @@ -15,7 +15,7 @@ def __init__(self, func, interval=0.1, threads=1, name=None): self.threads = [] self.stopped = Event() self.func, self.interval, self.thread_count = func, interval, threads - self.name = name if name else self.func.__name__ + self.name = name or self.func.__name__ on_startup(self.start) on_shutdown(self.stop)