简体   繁体   English

获取python脚本的运行时间

[英]Get the running time of python script

I wrote set of python scripts which runs as my back end. 我写了一套python脚本作为我的后端运行。 User have to upload a file using the web page that I have provided to them. 用户必须使用我提供给他们的网页上传文件。 I that web page there is a progress bar which shows the user how mach of processing done to there video file. 在该网页上,有一个进度栏,向用户显示如何处理该视频文件。 Because this video file break into frames and identify objects and save in the db. 因为此视频文件会分成几帧并标识对象并保存在数据库中。 Every things are works well except the progress bar. 除进度条外,其他所有操作均正常。 I need a way to indicate the user repeatedly until the script is completes. 我需要一种方法来重复指示用户,直到脚本完成。 But I do not have a way to do this. 但是我没有办法做到这一点。 I try to use 我尝试使用

start_time = time.time()

@app.route('/upload', methods=['POST'])
def upload_file():
filename = request.get_json()
print filename

fullPath = path + "/" + filename

print fullPath

fragmentation.framerate.calframerate(fullPath)

timeRunning = ("--- %s seconds ---" % (time.time() - start_time))

return timeRunning

but this will give the output after the script ends. 但这将在脚本结束后提供输出。 But I need to show the progress bar till the script ends. 但是我需要显示进度条,直到脚本结束。

Is there is a way to do this.Please help me 有办法吗请帮帮我

A progress bar would require async or threading. 进度条将需要异步或线程化。 Research these and give it a go. 研究这些并尝试一下。 You can't be actively performing tasks while a progress bar is being rendered unless you are ticking the progress bar up in a loop. 除非在循环中向上标记进度条,否则在渲染进度条时不能主动执行任务。 Which would be a better way to go about this. 这样做会是更好的方法。

Threading 穿线

Asyncio 异步

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM