我有一个CGI表单,它接受CSV表和电子邮件,并调用两个在后台运行的单独python脚本。执行大约需要15分钟。我想对这些脚本进行异步调用,以便我可以显示一些消息并防止apache超时。
这是我的代码
import os
import cgi, cgitb
import csv
import sys
import subprocess
import io
cgitb.enable()
form = cgi.FieldStorage()
filedata = form['file']
filecontent = filedata.file.read().splitlines()
email=form.getvalue('email_address')
email = str(email)
subprocess.Popen([sys.executable, 'giw.py', str(email)], shell=False,
stdin=None, stdout=None, stderr=None, close_fds=True)
subprocess.Popen([sys.executable, 'mailer.py', str(email)], shell=False,
stdin=None, stdout=None, stderr=None, close_fds=True)
答案 0 :(得分:0)
这对我有用: -
Run background process in Python and do NOT wait
import subprocess
import sys
subprocess.Popen([sys.executable, 'giw.py', str(email)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT);