我試圖用Celery(和rabbitmq)與Flask郵件異步發送郵件。最初,我從瓶子破碎芹菜的render_template問題 - Flask-Mail breaks Celery(芹菜任務仍然可以成功執行,但沒有電子郵件正在發送)。當我試圖解決這個問題時(這個問題還沒有解決!) - 我偶然發現了另一個問題。這是由於線程鎖定導致的酸洗錯誤。我注意到,當我改變稱爲芹菜任務的方式時(從延遲到apply_async),問題開始了。從那以後,我嘗試恢復我的改變,但仍然無法擺脫錯誤。任何有關任何問題的幫助將受到高度讚賞。燒瓶郵件給芹菜酸洗錯誤
回溯:
File "/Users/.../python2.7/site-packages/celery/app/amqp.py", line 250, in publish_task
**kwargs
File "/Users/.../lib/python2.7/site-packages/kombu/messaging.py", line 157, in publish
compression, headers)
File "/Users/.../lib/python2.7/site-packages/kombu/messaging.py", line 233, in _prepare
body) = encode(body, serializer=serializer)
File "/Users/.../lib/python2.7/site-packages/kombu/serialization.py", line 170, in encode
payload = encoder(data)
File "/Users/.../lib/python2.7/site-packages/kombu/serialization.py", line 356, in dumps
return dumper(obj, protocol=pickle_protocol)
PicklingError: Can't pickle <type 'thread.lock'>: attribute lookup thread.lock failed
tasks.py
from __future__ import absolute_import
from flask import render_template
from flask.ext.mail import Message
from celery import Celery
celery = Celery('tasks',
broker = 'amqp://tester:[email protected]:5672/test_host')
@celery.task(name = "send_async_email")
def send_auth_email(app, nickname, email):
with app.test_request_context("/"):
recipients = []
recipients.append(email)
subject = render_template("subject.txt")
msg = Message(subject, recipients = recipients)
msg.html = render_template("test.html", name = nickname)
app.mail.send(msg)
在測試情況下,我只要致電:
send_auth_email.delay(test_app, nick, email)
FYI:如果我不將API工作完全正常」不要使用芹菜(即同步)。提前致謝!
它是燒瓶應用程序的一個實例。僅供參考 - 我沒有celeryconfig.py文件和結果後端。這應該是一個問題嗎? – user2216194
不,這會導致更多的錯誤,這一點顯然不取決於此。根據你的回覆更新答案。 – alko