如题:使用多线程发送邮件时,给线程调用的回调函数传一个(类型为object,名字叫user)的参数时无法传入
错误信息为:
代码是:
from flask_mail import Message
from bigweb.extensions import mail
from threading import Thread
from flask import current_app
def send_email(app,user):
print(user) # 打印信息为 None
with app.app_context():
message = Message(subject="confirm email", recipients=[(user.username,user.email)],body="jsdjcjsdvn jkdfn jkdfn kjdf nkjfdn")
mail.send(message)
def send_tr_email(user):
print(user) # 打印信息为 <User 1>
app = current_app._get_current_object()
# message = Message(subject="confirm email",recipients=[(user.username,user.email)],body="jsdjcjsdvn jkdfn jkdfn kjdf nkjfdn")
tr = Thread(target=send_email,args=[app,user])
tr.start()