显示PYTHON CGI脚本的进度 [英] Show progress of PYTHON CGI script

查看:122
本文介绍了显示PYTHON CGI脚本的进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 PYTHON CGI脚本(内容类型:文本/纯文本),该脚本大约需要执行10分钟。
我想在浏览器上查看脚本的执行状态。

I have a PYTHON CGI script(Content-type: text/plain) which takes about 10 minutes to execute. I want to see the execution status of my script on my browser .

像下面这样:


已执行脚本的第一部分...

Part 1 of script executed...

已执行脚本的第二部分..

Part 2 of script executed..

脚本的第3部分已执行。

Part 3 of script executed..

执行完成

我正在使用打印语句,但是它仅在脚本完成执行后才全部输出所有打印语句,而不是一个接一个地输出。

I am using print statements, but it is outputting all the print statements all-together only after the script has completed execution, and not one by one.

请帮助..

推荐答案

尝试做:

import sys
...

print "Part 1 of script executed..."
sys.stdout.flush() # do this after the print

这会刷新标准输出缓冲区,这可能是您遇到的问题之一。您的浏览器或网络服务器也很可能导致此现象,在这种情况下,解决此问题将更加困难。

This flushes the standard out buffer, which could be the cause of one of your issues. It is also very likely that your browser or webserver might be causing this behavior, in which case solving this problem will be more difficult.

我不确定您要在这里做什么,但是您可能想使用AJAX异步启动脚本,然后异步加载回数据。对于浏览器和Web服务器来说,这比处理cgi脚本要花几分钟的时间更好。

I'm not sure what you are trying to do here, but you may want to use AJAX to asynchronously fire off your script and then asynchronously load the data back. This is better behavior for browsers and webservers to handle than a cgi script taking several minutes.

这篇关于显示PYTHON CGI脚本的进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆