当我从 cmd 运行我的应用程序时,我可以非常快速地调用 api 。但是当它托管在 IIS (fastcgi - wfastcgi.py) 中时,运行需要很长时间,我无法从 api 获得任何回报。
import flask
app = flask.Flask(__name__)
app.config["DEBUG"] = True
app.config['UPLOAD_FOLDER'] = 'holding'
@app.route('/test', methods=['GET', 'POST'])
def test():
import subprocess
import os
import re
libreoffice_exe = 'C:/Program Files/LibreOffice/program/soffice'
inputFileName = r'D:\folder\some_powerpoint_file.pptx'
outputFileName = r'D:\folder\output.pdf'
inputFileName = re.sub('\\\\', '/', inputFileName)
outputFileName = re.sub('\\\\', '/', outputFileName)
outputFileDir = os.path.dirname(outputFileName)
call_item = [libreoffice_exe, '--headless', '--convert-to', 'pdf', inputFileName, '--outdir', outputFileDir]
proc = subprocess.Popen(
call_item,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
proc.wait()
(stdout, stderr) = proc.communicate()
if proc.returncode != 0:
print(str(stdout))
print(str(stderr))
return 'fail'
return 'success'
if __name__ == '__main__':
app.run()
我没有从 stderr/stdout 得到任何错误输出。它只是无限期地运行(直到超时)