完成100%完成时更改进度栏文本
在此示例中,总进度为5秒(我正在构建一个可延展的模型,我可以使用任何可以使用相同的总数的秒数):
from rich.progress import Progress
import time
import sys
def main(timeout):
start_time = time.time()
penultimate_quarter = timeout-1
with Progress() as progress:
task1 = progress.add_task("[green]Processing...", total=100)
while not progress.finished:
progress.update(task1, advance=100/penultimate_quarter)
time.sleep(1)
time.sleep(1)
progress.update(task1, description="[blue]Complete Task", advance=100)
print("--- %s seconds ---" % (time.time() - start_time))
if __name__ == "__main__":
main(5)
output(同一行):
但是我想要的输出不包含此100%
带有消息处理...
:
progress.fineded
用我可以将其放入已经传递了多少个价值的方法并暂停了循环,例如:
penultimate_quarter = timeout-1
while progress.total_advance <= (penultimate_quarter/timeout):
# rest of code...
我如何根据 rich 用法?
In this example the total progress is 5 seconds (I'm building a model that can be malleable, that I can use any amount of total seconds that will work the same):
from rich.progress import Progress
import time
import sys
def main(timeout):
start_time = time.time()
penultimate_quarter = timeout-1
with Progress() as progress:
task1 = progress.add_task("[green]Processing...", total=100)
while not progress.finished:
progress.update(task1, advance=100/penultimate_quarter)
time.sleep(1)
time.sleep(1)
progress.update(task1, description="[blue]Complete Task", advance=100)
print("--- %s seconds ---" % (time.time() - start_time))
if __name__ == "__main__":
main(5)
Output (same line):
But the output I wanted does not contain this 100%
with the message Processing...
:
I tried to find a way to replace the progress.finished
with a method that I could put in how many quarters of value have already been passed and pause the looping, something like:
penultimate_quarter = timeout-1
while progress.total_advance <= (penultimate_quarter/timeout):
# rest of code...
How can I make this correctly and professionally according to rich usage?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
修改1:对象值定义总进度
之前:
After:
修改2:
time.sleep
之前的位置和使用之前:after:
after:
最终代码:
输出(更新同一行):
Modification 1: Object value defining total progress
Before:
After:
Modification 2: position and use of
time.sleep
Before:
After:
Final Code:
Output (update same line):