V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
chaleaoch
V2EX  ›  Python

celery worker 跑跑就不工作了. 如何 debug?

  •  
  •   chaleaoch · 2020-12-17 17:14:50 +08:00 · 2123 次点击
    这是一个创建于 1227 天前的主题,其中的信息可能已经有所发展或是发生改变。
    大佬给指条明路.

    rabbitmq 好好的. 因为 beat 不停的发消息. 成功的.
    现在是消费者挂了,但是进程还在啊.
    9 条回复    2020-12-25 16:38:36 +08:00
    northisland
        1
    northisland  
       2020-12-17 17:34:16 +08:00
    不搞架构,但用过 celery,纯属业余

    我记得把 celery.tasks 里的函数,可以直接放在 test.py 的主函数里,按照 log 过一遍可疑的 mq 输入,应该能搞定复现。
    northisland
        2
    northisland  
       2020-12-17 17:41:00 +08:00
    @celery.task
    的函数可以直接运行,不用连队列。
    4everLoveU
        3
    4everLoveU  
       2020-12-17 17:47:24 +08:00
    1 、celery 启动有 debug 模式,打印的内容还是比较详细的;
    2 、重载一下 celery.Task,自己实现 on_failure 功能,看看 trace

    ```python
    class CustomTask(celery.Task):

    ...

    def on_failure(self, exc, event_id, args, kwargs, einfo):
    # do something
    ```
    cz5424
        4
    cz5424  
       2020-12-17 17:47:41 +08:00 via iPhone
    看看是不是有耗时很久的队列,一直卡着走不动,比如 requests 没写 timeout
    chenqh
        5
    chenqh  
       2020-12-17 17:47:49 +08:00
    有什么 log?
    abersheeran
        6
    abersheeran  
       2020-12-18 09:21:12 +08:00
    Celery 可以让你自己写代码反馈 Task 的进度,用这个 DEBUG,你就知道它卡在哪儿了。
    seven123
        7
    seven123  
       2020-12-18 10:46:46 +08:00
    之前用过 celery 貌似不太稳定?,可能会出现内存泄露的事情, 所以我会加上这个参数 。
    celery 在长时间运行后可能出现内存泄漏,每个 worker 执行 5 个任务就死掉
    CELERYD_MAX_TASKS_PER_CHILD = 5
    HashV2
        8
    HashV2  
       2020-12-18 13:12:49 +08:00
    @chaleaoch task 中直接 print 出来任务执行相关情况 celery 启动的时候添加-f 参数指定日志文件 有问题及时查看日志

    @seven123 不错的参数 加上了
    nano91
        9
    nano91  
       2020-12-25 16:38:36 +08:00
    进 flower 看一下每个 worker 的情况,7 楼的情况也有可能
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5304 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 07:28 · PVG 15:28 · LAX 00:28 · JFK 03:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.