bug fix + better closing procedure ofr PBars
This commit is contained in:
@@ -62,7 +62,7 @@ class PBars:
|
|||||||
kwargs["desc"] = kwargs["desc"].format(worker_id=i)
|
kwargs["desc"] = kwargs["desc"].format(worker_id=i)
|
||||||
self.append(tqdm(position=i, ncols=100, ascii=False, **kwargs))
|
self.append(tqdm(position=i, ncols=100, ascii=False, **kwargs))
|
||||||
self.print_path = Path("progress " + self.pbars[0].desc).resolve()
|
self.print_path = Path("progress " + self.pbars[0].desc).resolve()
|
||||||
self.open = True
|
self.close_ev = threading.Event()
|
||||||
if "file" in self.policy:
|
if "file" in self.policy:
|
||||||
self.thread = threading.Thread(target=self.print_worker, daemon=True)
|
self.thread = threading.Thread(target=self.print_worker, daemon=True)
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
@@ -77,10 +77,8 @@ class PBars:
|
|||||||
|
|
||||||
def print_worker(self):
|
def print_worker(self):
|
||||||
while True:
|
while True:
|
||||||
for _ in range(100):
|
if self.close_ev.wait(2.0):
|
||||||
if not self.open:
|
return
|
||||||
return
|
|
||||||
time.sleep(0.02)
|
|
||||||
self.print()
|
self.print()
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
@@ -115,7 +113,7 @@ class PBars:
|
|||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.print()
|
self.print()
|
||||||
self.open = False
|
self.close_ev.set()
|
||||||
if "file" in self.policy:
|
if "file" in self.policy:
|
||||||
self.thread.join()
|
self.thread.join()
|
||||||
for pbar in self.pbars:
|
for pbar in self.pbars:
|
||||||
@@ -146,9 +144,8 @@ class ProgressBarActor:
|
|||||||
self.counters[worker_id] = rel_pos
|
self.counters[worker_id] = rel_pos
|
||||||
|
|
||||||
def update_pbars(self):
|
def update_pbars(self):
|
||||||
for counter, pbar in zip(self.counters, self.p_bars):
|
for counter, pbar in zip(self.counters, self.p_bars.pbars):
|
||||||
pbar.update(counter - pbar.n)
|
pbar.update(counter - pbar.n)
|
||||||
self.p_bars.print()
|
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.p_bars.close()
|
self.p_bars.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user