PEP 8 and stuff

This commit is contained in:
enkore 2013-03-11 00:21:54 +01:00
parent c259a653ae
commit a5b274fd23
3 changed files with 15 additions and 12 deletions

View File

@ -15,7 +15,7 @@ class Manager:
separate = [] separate = []
for thread in self.threads: for thread in self.threads:
separate.extend(thread.branch(thread.time, self.upper_bound)) 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): def __repr__(self):
return "Manager" return "Manager"
@ -23,12 +23,11 @@ class Manager:
def wrap(self, workload): def wrap(self, workload):
return wrapper.WorkloadWrapper(wrapper.ExceptionWrapper(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) return partition(workloads, self.lower_bound, lambda workload: workload.time)
def create_threads(self, threads): def create_threads(self, threads):
for workloads in threads: for workloads in threads: self.create_thread(workloads)
self.create_thread(workloads)
def create_thread(self, workloads): def create_thread(self, workloads):
thread = threads.Thread(self.target_interval, workloads, start_barrier=0) thread = threads.Thread(self.target_interval, workloads, start_barrier=0)
@ -39,5 +38,4 @@ class Manager:
self.threads[0].append(self.wrap(workload)) self.threads[0].append(self.wrap(workload))
def start(self): def start(self):
for thread in self.threads: for thread in self.threads: thread.start()
thread.start()

View File

@ -36,16 +36,18 @@ class Thread(threading.Thread):
while len(self) <= self.start_barrier: while len(self) <= self.start_barrier:
time.sleep(0.4) time.sleep(0.4)
def setproctitle(self): def set_thread_title(self):
setproctitle("i3pystatus {name}: {workloads}".format(name=self.name, workloads=list(map(repr, self.workloads)))) setproctitle("i3pystatus {name}: {workloads}".format(
name=self.name,
workloads=list(map(repr, self.workloads))
))
def execute_workloads(self): def execute_workloads(self):
for workload in self: for workload in self: workload()
workload()
self.workloads.sort(key=lambda workload: workload.time) self.workloads.sort(key=lambda workload: workload.time)
def run(self): def run(self):
self.setproctitle() self.set_thread_title()
while self: while self:
self.execute_workloads() self.execute_workloads()
filltime = self.target_interval - self.time filltime = self.target_interval - self.time

View File

@ -17,7 +17,10 @@ class ExceptionWrapper(Wrapper):
try: try:
self.workload() self.workload()
except BaseException as exc: 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) traceback.print_exception(*sys.exc_info(), file=sys.stderr)
sys.stderr.flush() sys.stderr.flush()