推荐学习书目
› 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
TheCure
V2EX  ›  Python

Python Celery 中每一个任务只会落到一个 worker 上吗?

  •  
  •   TheCure · Sep 17, 2016 · 4460 views
    This topic created in 3661 days ago, the information mentioned may be changed or developed.

    需要确保一个任务只能执行一次,找到了一下两篇资料

    1.http://docs.celeryproject.org/en/latest/tutorials/task-cookbook.html#ensuring-a-task-is-only-executed-one-at-a-time
    
    2.http://loose-bits.com/2010/10/distributed-task-locking-in-celery.html
    

    问题 1:

    貌似都是通过 acquire lock 来实现的,但是实际上我没用加锁的方式,也没遇到过同一个任务被运行两次的情况,加锁只是为了 ensure 吗,不加也没多关系?

    问题 2:

    celery 如果是分布式的,那 celery 是怎么做到一个任务只落到一个 celery 实例上的?使用 mq 的 lock 来保证的吗?redis 和 rmq 都能保证这一点吗

    2 replies  •  2016-09-17 22:44:23 +08:00
    bramblex
        1
    bramblex  
       Sep 17, 2016 via Android
    你没发现你现在是集中式的设计方案,却企图用分布式的方式实现吗?
    julyclyde
        2
    julyclyde  
       Sep 17, 2016 via iPad
    redis broker 应该是 lpush rpop 这样的,并不需要加索啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   882 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 22:13 · PVG 06:13 · LAX 15:13 · JFK 18:13
    ♥ Do have faith in what you're doing.