简体   繁体   English

在使用CGI的python 2.7中,如何检查分叉过程是否完成

[英]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.

相关问题 如何检查pointsD是否在多边形python 2.7的行内(不导入) - How to check whether a pointsD is within the lines of a polygon python 2.7 (no import) VScode:如何调试python 2.7 cgi脚本? - VScode: How to debug a python 2.7 cgi script? 如何使用Python 2.7(可能还有pyserial)检查Linux中的串口是否已经打开(通过其他进程)? - How to check if serial port is already open (by another process) in Linux, using Python 2.7 (and possibly pyserial)? 使用Python2.7的CGI - CGI with Python2.7 Tensorflow GPU 在与 Python 2.7 的 multiprocessing.Process 调用分叉的新进程中不可用 - Tensorflow GPU not available in a new process forked off with Python 2.7's multiprocessing.Process call Python-wget检查进程何时完成 - Python - wget check when process has completed 如何知道一个 nifi 进程组是否已经使用 nipyapi 完成了数据传输? - How to know whether a nifi process group has completed the data transfer using nipyapi? 如何使用python检查文件夹是否为快捷方式? - How to check whether a folder is a shortcut or not using python? 如何使用 python 检查文件夹是否为空? - How to check whether a folder is empty or not using python? 检查Python 2.7和3.x中的变量是int还是long - Check whether variable is int or long in Python 2.7 and 3.x
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM