From a5b274fd23fe8cde8dd68256d1d5bf5b83aadfbf Mon Sep 17 00:00:00 2001 From: enkore Date: Mon, 11 Mar 2013 00:21:54 +0100 Subject: [PATCH] PEP 8 and stuff --- i3pystatus/core/threading/manager.py | 10 ++++------ i3pystatus/core/threading/threads.py | 12 +++++++----- i3pystatus/core/threading/wrapper.py | 5 ++++- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/i3pystatus/core/threading/manager.py b/i3pystatus/core/threading/manager.py index 37de489..0712ec9 100644 --- a/i3pystatus/core/threading/manager.py +++ b/i3pystatus/core/threading/manager.py @@ -15,7 +15,7 @@ class Manager: separate = [] for thread in self.threads: separate.extend(thread.branch(thread.time, self.upper_bound)) - self.create_threads(self.partition(separate)) + self.create_threads(self.partition_workloads(separate)) def __repr__(self): return "Manager" @@ -23,12 +23,11 @@ class Manager: def wrap(self, workload): return wrapper.WorkloadWrapper(wrapper.ExceptionWrapper(workload)) - def partition(self, workloads): + def partition_workloads(self, workloads): return partition(workloads, self.lower_bound, lambda workload: workload.time) def create_threads(self, threads): - for workloads in threads: - self.create_thread(workloads) + for workloads in threads: self.create_thread(workloads) def create_thread(self, workloads): thread = threads.Thread(self.target_interval, workloads, start_barrier=0) @@ -39,5 +38,4 @@ class Manager: self.threads[0].append(self.wrap(workload)) def start(self): - for thread in self.threads: - thread.start() + for thread in self.threads: thread.start() diff --git a/i3pystatus/core/threading/threads.py b/i3pystatus/core/threading/threads.py index 7718ff1..38eaf76 100644 --- a/i3pystatus/core/threading/threads.py +++ b/i3pystatus/core/threading/threads.py @@ -36,16 +36,18 @@ class Thread(threading.Thread): while len(self) <= self.start_barrier: time.sleep(0.4) - def setproctitle(self): - setproctitle("i3pystatus {name}: {workloads}".format(name=self.name, workloads=list(map(repr, self.workloads)))) + def set_thread_title(self): + setproctitle("i3pystatus {name}: {workloads}".format( + name=self.name, + workloads=list(map(repr, self.workloads)) + )) def execute_workloads(self): - for workload in self: - workload() + for workload in self: workload() self.workloads.sort(key=lambda workload: workload.time) def run(self): - self.setproctitle() + self.set_thread_title() while self: self.execute_workloads() filltime = self.target_interval - self.time diff --git a/i3pystatus/core/threading/wrapper.py b/i3pystatus/core/threading/wrapper.py index 08a1d30..69e833c 100644 --- a/i3pystatus/core/threading/wrapper.py +++ b/i3pystatus/core/threading/wrapper.py @@ -17,7 +17,10 @@ class ExceptionWrapper(Wrapper): try: self.workload() except BaseException as exc: - sys.stderr.write("Exception in {thread}".format(thread=threading.current_thread().name)) + sys.stderr.write("Exception in {thread} at {time}\n".format( + thread=threading.current_thread().name, + time=time.strftime("%c") + )) traceback.print_exception(*sys.exc_info(), file=sys.stderr) sys.stderr.flush()