Skip to content

Commit dfa041f

Browse files
committed
修复进度条不显示结尾提示,无法更换输出流的bug
1 parent e24995c commit dfa041f

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/PaperCrawlerUtil/common_util.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ def __init__(self, final_prompt="", iterable=None, desc=None, total=-1, leave=Tr
111111
self.desc = desc
112112
self.total = total
113113
self.leave = leave
114-
self.file = file
114+
self.file = global_val.get_value(KEEP_PROCESS_BAR_STYLE_FILE) \
115+
if global_val.get_value(KEEP_PROCESS_BAR_STYLE) else file
115116
self.ncols = ncols
116117
self.mininterval = mininterval
117118
self.maxinterval = maxinterval
@@ -148,7 +149,7 @@ def process(self, *args):
148149
, delay=self.delay, gui=self.gui)
149150
else:
150151
self.batch = args[1]
151-
if self.current + self.batch > self.total:
152+
if self.current + self.batch >= self.total:
152153
self.bar.update(self.total - self.current)
153154
self.current = self.total
154155
self.bar.set_postfix_str(self.final_prompt)
@@ -716,15 +717,12 @@ def __str__(self) -> str:
716717
def __repr__(self) -> str:
717718
return super().__repr__()
718719

719-
if __name__ == "__main__":
720-
basic_config(logs_style=LOG_STYLE_PRINT)
721-
bar = process_bar()
722-
bar.process(0, 1, 100)
723-
for i in range(100):
724-
bar.process(0, 1, 100)
725-
log("ahfu")
726-
time.sleep(0.1)
727-
# for batch in tqdm(range(100), total=100, position=0, file=sys.stdout, desc="desc"):
728-
# if batch % 5 == 0:
729-
# tqdm.write(str(batch))
730-
# time.sleep(1)
720+
# if __name__ == "__main__":
721+
# basic_config(logs_style=LOG_STYLE_PRINT, keep_process_bar_style_file=sys.stdout)
722+
# bar = process_bar(final_prompt="wancheng")
723+
# bar.process(0, 1, 100)
724+
# for i in range(100):
725+
# bar.process(0, 1, 100)
726+
# log("ahfu")
727+
# time.sleep(0.1)
728+

0 commit comments

Comments
 (0)