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
TheCure
V2EX  ›  Python

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

  •  
  •   TheCure · 2016-09-17 12:45:54 +08:00 · 3889 次点击
    这是一个创建于 2791 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    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 条回复    2016-09-17 22:44:23 +08:00
    bramblex
        1
    bramblex  
       2016-09-17 13:24:23 +08:00 via Android
    你没发现你现在是集中式的设计方案,却企图用分布式的方式实现吗?
    julyclyde
        2
    julyclyde  
       2016-09-17 22:44:23 +08:00 via iPad
    redis broker 应该是 lpush rpop 这样的,并不需要加索啊
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3192 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 12:55 · PVG 20:55 · LAX 05:55 · JFK 08:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.