启动worker:
celery -A tasks worker --loglevel=error --pool=solo
worker启动成功
启动beat
celery -A tasks beat --loglevel=info
beat启动成功
启动flower
celery -A tasks flower --loglevel=info
flower启动成功,然后进入http://localhost:5555 可以看得到现在的任务执行状况
flower很好用,可以清楚的看到报错的内容
启动worker后如果有这个信息:
Events of group {task} enabled by remote
它表示远程开启了任务事件监控功能。因此,当您的任务执行时,能够通过系统事件监视工具及时了解任务的执行状况,更及时地处理可能出现的问题。
一些常用的celery命令
- 启动 worker:`celery -A tasks worker --loglevel=INFO`
- 启动 beat 定时任务调度程序:`celery -A tasks beat --loglevel=INFO`
- 停止 worker 或 beat:`celery control stop worker` 或 `celery control stop beat`
- 启动并行 worker:`celery -A tasks worker -c 4 --loglevel=INFO`
- 清除 worker 队列:`celery -A tasks purge`
报错内容如下:
Task handler raised error: ValueError('not enough values to unpack (expected 3, got 0)')
Traceback (most recent call last):
File "d:\python\lib\site-packages\billiard\pool.py", line 362, in workloop
result = (True, prepare_result(fun(*args, **kwargs)))
File "d:\python\lib\site-packages\celery\app\trace.py", line 638, in fast_trace_task
tasks, accept, hostname = _loc
ValueError: not enough values to unpack (expected 3, got 0)
确认过代码没有问题,找了很多办法都没有用
后来在运行worker的时候加上--pool=solo,解决了!
celery -A tasks worker --loglevel=error --pool=solo