新建tasks.py
import time
from celery import Celery
celery = Celery('tasks', broker='redis://127.0.0.1:6379/0')
@celery.task
def sendmail(mail):
print(mail)
print('sending mail to %s...' % mail['to'])
time.sleep(2.0)
print('mail sent.')
if __name__ == '__main__':
pass
celery -A tasks worker --loglevel=info
新建发送邮件模块
from tasks import sendmail
sendmail.delay(dict(to='123@qq.com'))
sendmail.delay(dict(to='456@qq.com'))
sendmail.delay(dict(to='789@qq.com'))
if __name__ == '__main__':
pass
运行
终端报错
[tasks]
. tasks.sendmail
[2021-07-21 14:46:11,308: INFO/MainProcess] Connected to redis://127.0.0.1:6379/0
[2021-07-21 14:46:11,355: INFO/MainProcess] mingle: searching for neighbors
[2021-07-21 14:46:12,488: INFO/MainProcess] mingle: all alone
[2021-07-21

这篇博客记录了在使用Celery进行异步任务处理时遇到的错误:`ValueError('not enough values to unpack (expected 3, got 0)')`。作者通过在启动Celery命令中添加`-P eventlet`参数,成功解决了问题,确保了任务的正常执行。
最低0.47元/天 解锁文章
1079





