如何在后台运行python函数并继续主流?

时间:2018-03-22 17:17:32

标签: python

我目前使用Flask创建网站。用户注册后,我想发送邮件&执行insert到sql,但它运行缓慢,所以我想在后台执行它仍然继续主流并返回html而不会卡在加载页面上。

def send_email_and_insert():
    # some smtplib code here
    # and some insert into sql too
    # this  function make the web stuck loading 5-10 second


@app.route('/sign_up/')
def sign_up():
    # some code here
    send_email_and_insert()
    return render_template('thanks_for_sign_up.html')

我认为可以通过多处理或线程来完成,但我无法做到正确。或者还有另一种解决方案?

0 个答案:

没有答案