Skip to content

Commit

Permalink
Merge pull request #22 from magfest/thread_name_overrides
Browse files Browse the repository at this point in the history
add override for thread names for DaemonTasks
  • Loading branch information
binary1230 authored Aug 21, 2016
2 parents e1fe2c9 + f2ead43 commit 435afc7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions sideboard/lib/_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 or self.func.__name__

on_startup(self.start)
on_shutdown(self.stop)

Expand All @@ -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)
Expand Down

0 comments on commit 435afc7

Please sign in to comment.