Python 3.x 如何找出python搜索文件需要多长时间?
所以我有一个小应用程序可以搜索我电脑上的所有xml文件,将文件名为44位的文件复制到“output”文件夹 问题在于,最终用户需要指示任务的进度和剩余时间 这是复制文件的模块: xml_search.py 下面的代码使用库并显示 指示任务的进度和剩余时间 您需要将上面修改过的代码添加到您的代码中。 因此,在您的情况下,您需要计算文件的数量,并将其作为Python 3.x 如何找出python搜索文件需要多长时间?,python-3.x,progress-bar,python-multithreading,python-os,time-estimation,Python 3.x,Progress Bar,Python Multithreading,Python Os,Time Estimation,所以我有一个小应用程序可以搜索我电脑上的所有xml文件,将文件名为44位的文件复制到“output”文件夹 问题在于,最终用户需要指示任务的进度和剩余时间 这是复制文件的模块: xml_search.py 下面的代码使用库并显示 指示任务的进度和剩余时间 您需要将上面修改过的代码添加到您的代码中。 因此,在您的情况下,您需要计算文件的数量,并将其作为ProgressBar构造函数的maxval参数的输入,然后删除sleep调用 建议的带有进度条的解决方案应使用一个线程。如果坚持使用多个线程,则需
ProgressBar
构造函数的maxval
参数的输入,然后删除sleep
调用
建议的带有进度条的解决方案应使用一个线程。如果坚持使用多个线程,则需要确定如何启动进度条以及将更新放在何处。尝试实现如下计时器装饰器:
import time
def mytimer(func):
def wrapper():
t1 = time.time()
result = func()
t2 = time.time()
print(f"The function {func.__name__} was run {t2 - t1} seconds")
return result
return wrapper
@mytimer
def TimeConsumingFunction():
time.sleep(3)
print("Hello timers")
TimeConsumingFunction()
输出:
/usr/bin/python3.7 /home/user/Documents/python-workspace/timers/example.py
Hello timers
The function TimeConsumingFunction was run 3.002610206604004 seconds
Process finished with exit code 0
这不显示进度,只显示经过的时间
import time
def mytimer(func):
def wrapper():
t1 = time.time()
result = func()
t2 = time.time()
print(f"The function {func.__name__} was run {t2 - t1} seconds")
return result
return wrapper
@mytimer
def TimeConsumingFunction():
time.sleep(3)
print("Hello timers")
TimeConsumingFunction()
/usr/bin/python3.7 /home/user/Documents/python-workspace/timers/example.py
Hello timers
The function TimeConsumingFunction was run 3.002610206604004 seconds
Process finished with exit code 0