在呈现pag后在Django中执行函数

2024-04-26 05:35:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道在呈现Django页面后是否有执行命令的方法

我有一个系统,我将电话培训变量设置为False,并使用subprocess.Popen运行命令行,我必须等待命令以.communicate()结束,然后说电话培训变量为True,但执行该命令大约需要15分钟,因此,我希望在执行命令后立即呈现页面。我的代码如下:

def GerarTreinoTelefonia(request):
    global treinamentotelefonia
    if treinamentotelefonia == False:
        if request.method == 'POST':
            treinamentotelefonia = True
            treinotelefonia = subprocess.Popen(shlex.split('python -m rasa_nlu.train -c chatbot/config/config_nlu.yml --data chatbot/dados/ilhas/telefonia/ -o /code/chatbot/models/telefonia --fixed_model_name nlu --project current --verbose'))
            return render(request, 'website/PainelGerenciamento.html')
            treinotelefonia.communicate()
            treinamentotelefonia = False

你知道我怎么做吗


Tags: 命令falsetrueifrequest页面执行命令电话