3.12: More bullet-proof wrapper
This commit is contained in:
parent
b42cd6aa15
commit
0a32494ce8
@ -14,7 +14,7 @@ class Manager:
|
|||||||
def __call__(self):
|
def __call__(self):
|
||||||
separate = []
|
separate = []
|
||||||
for thread in self.threads:
|
for thread in self.threads:
|
||||||
separate.extend(self.branch(thread, thread.time))
|
separate.extend(thread.branch(thread.time, self.upper_bound))
|
||||||
self.create_threads(self.partition(separate))
|
self.create_threads(self.partition(separate))
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@ -23,12 +23,6 @@ class Manager:
|
|||||||
def wrap(self, workload):
|
def wrap(self, workload):
|
||||||
return wrapper.WorkloadWrapper(wrapper.ExceptionWrapper(workload))
|
return wrapper.WorkloadWrapper(wrapper.ExceptionWrapper(workload))
|
||||||
|
|
||||||
def branch(self, thread, vtime):
|
|
||||||
if len(thread) > 1 and vtime > self.upper_bound:
|
|
||||||
remove = thread.pop()
|
|
||||||
return [remove] + self.branch(thread, vtime - remove.time)
|
|
||||||
return []
|
|
||||||
|
|
||||||
def partition(self, workloads):
|
def partition(self, workloads):
|
||||||
return partition(workloads, self.lower_bound, lambda workload: workload.time)
|
return partition(workloads, self.lower_bound, lambda workload: workload.time)
|
||||||
|
|
||||||
|
@ -51,3 +51,9 @@ class Thread(threading.Thread):
|
|||||||
filltime = self.target_interval - self.time
|
filltime = self.target_interval - self.time
|
||||||
if filltime > 0:
|
if filltime > 0:
|
||||||
time.sleep(filltime)
|
time.sleep(filltime)
|
||||||
|
|
||||||
|
def branch(self, vtime, bound):
|
||||||
|
if len(self) > 1 and vtime > bound:
|
||||||
|
remove = self.pop()
|
||||||
|
return [remove] + self.branch(vtime - remove.time, bound)
|
||||||
|
return []
|
||||||
|
@ -16,7 +16,7 @@ class ExceptionWrapper(Wrapper):
|
|||||||
def __call__(self):
|
def __call__(self):
|
||||||
try:
|
try:
|
||||||
self.workload()
|
self.workload()
|
||||||
except Exception as exc:
|
except BaseException as exc:
|
||||||
sys.stderr.write("Exception in {thread}".format(thread=threading.current_thread().name))
|
sys.stderr.write("Exception in {thread}".format(thread=threading.current_thread().name))
|
||||||
traceback.print_exception(*sys.exc_info(), file=sys.stderr)
|
traceback.print_exception(*sys.exc_info(), file=sys.stderr)
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
Loading…
Reference in New Issue
Block a user