线程后未调用烧瓶render_template

时间:2020-03-30 13:32:32

标签: python flask

我目前有一个app.route,当它被触发时,它会启动一个线程并假设要返回一个模板。但是,它当前不返回模板,但是如果我注释掉线程,它将返回。有什么解决方法吗?

@app.route('/start', methods=['POST'])
def start():
    windowname = request.form['windowname']
    Thread(target = runBot(windowname)).start() #when commented out the next line is called
    return render_template('bot.html', isActive = True) #this line isn't being called

1 个答案:

答案 0 :(得分:0)

我认为问题是您在调用函数而不是将其传递给线程。试试这个:

@app.route('/start', methods=['POST'])
def start():
    windowname = request.form['windowname']
    Thread(target=runBot, args=(window,)).start() # pass the function, and the argument in the args parameter
    return render_template('bot.html', isActive = True)