[英]In python 2.7 using CGI, how to check whether forked process completed
So I have a set of python scripts. 所以我有一套python脚本。 In an attempt to make a simple GUI, I have been combining html and CGI. 为了制作一个简单的GUI,我一直将html和CGI结合在一起。 So far so good. 到现在为止还挺好。 However, one of my scripts takes a long time to complete (>2 hours). 但是,我的脚本之一需要很长时间才能完成(> 2小时)。 So obviously, when I run this on my server (localhost on mac) I get a "gateway timeout error". 所以很明显,当我在服务器(在Mac上为localhost)上运行此命令时,出现“网关超时错误”。 I was reading about forking the sub process, and checking whether the process completed. 我正在阅读有关分叉子流程,并检查该流程是否完成的信息。
This is what I came up with, but it isn't working :(. 这是我想出的,但是没有用:(。
import os, time
#upstream stuff happening as part of main script
pid=os.fork()
if pid==0:
os.system("external_program") #this program will make "text.txt" as output
exit()
while os.stat(""text.txt").st_size == 0: # check whether text.txt has been written, if not print "processing" and continue to wait
print "processing"
sys.stdout.flush()
time.sleep(300)
#downstream stuff happening
As alwas, any help is appreciated 一直以来,任何帮助都值得赞赏
Did you try this one: 您是否尝试过以下一种方法:
import os
processing = len(os.popen('ps aux | grep yourscript.py').readlines()) > 2
It tells you if your script is still running (returns boolean value). 它告诉您脚本是否仍在运行(返回布尔值)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.