从烧瓶超时运行python脚本

时间:2020-03-25 12:15:12

标签: python nginx flask gunicorn

我从烧瓶中启动了一个python脚本,该脚本可能需要一些时间才能执行,因为在后台它需要处理大文件。

from flask import Flask, render_template, request, redirect, url_for
from transcode_audio_manual_stag_funct import get_epguid

application = Flask(__name__)

@application.route('/audiotranscode')
def homepage():
    html = render_template('homepage.html')
    return html

@application.route('/transcode', methods=['GET','POST'])
def transcode():
    dmguid = request.form['mediaid']
    get_epguid(dmguid)
    return redirect(url_for('homepage'))

if __name__ == '__main__':
    application.run(host='0.0.0.0')

我使用Gunicorn和nginx来运行该应用程序。我必须将超时值都设置得很高,否则我会在gunicorn上收到工作人员超时,或者在nginx上收到504网关超时。但这似乎不是解决此问题的最有效方法。有没有更好的方法来避免超时或从烧瓶中启动脚本?

0 个答案:

没有答案