Flask发QQ邮件太慢了(即使是异步),原本150ms响应的页面加了邮件变成了5s,请问各位大神有没有比较简单的解决方法?
现在我很疑惑的是,既然我已经新开一个线程来发邮件,按理视图业务不会等待他发送完邮件而会直接继续响应,但是实际情况是视图业务被阻塞了5s
部分代码(按照狗书写的):
def send_async_email(app, msg): with app.app_context(): mail.send(msg)def send_email(to, subject, template, **kwargs): app = current_app._get_current_object() msg = Message(app.config['FLASKY_MAIL_SUBJECT_PREFIX'] + subject, sender=app.config['FLASKY_MAIL_SENDER'], recipients=[to]) msg.body = render_template(template + '.txt', **kwargs) msg.html = render_template(template + '.html', **kwargs) thr = Thread(target=send_async_email, args=[app, msg]) thr.start() return thr
天涯尽头无女友
相关分类