In python 2.7 using CGI, how to check whether forked process completed
<p>So I have a set of python scripts. In an attempt to make a simple GUI, I have been combining html and CGI. So far so good. However, one of my scripts takes a long time to complete (>2 hours). So obviously, when I run this on my server (localhost on mac) I get a "gateway timeout error". I was reading about forking the sub process, and checking whether the process completed.<br>
This is what I came up with, but it isn't working :(.</p>

<pre><code>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
</code></pre>

<p>As alwas, any help is appreciated</p>

<p>Did you try this one:</p>

<pre><code>import os
processing = len(os.popen('ps aux | grep yourscript.py').readlines()) &gt; 2
</code></pre>

<p>It tells you if your script is still running (returns boolean value).</p>

python subprocess cgi