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

关于 celery 在 windows 下不能进行 time limit(超时限制)的解决办法

  •  
  •   akmonde · Mar 17, 2017 · 4124 views
    This topic created in 3366 days ago, the information mentioned may be changed or developed.
    曾经在配置文件里设置了超时限制, CELERYD_TASK_SOFT_TIME_LIMIT ,本来在 Linux 下是能用的。

    当然,这里插一句,也曾经设置过 CELERY_TASK_RESULT_EXPIRES 和 CELERYD_TASK_TIME_LIMIT ,不过没起作用。

    后来因为某些原因,程序迁移到了 windows 下,结果发现报错如下:
    UserWarning: Soft timeouts are not supported: on this platform: It does not have the SIGUSR1 signal.&*

    查了下文档:
    http://docs.celeryproject.org/en/latest/userguide/workers.html#time-limits
    发现:
    "Time limits do not currently work on Windows and other platforms that do not support the SIGUSR1 signal."

    另外看了下,在 @app.task()这样的形式,去在括号里添加 timeout 和 time limit 之类的内容,据说也是不行的。

    那么问题来了,难道 windows 下 celery 无法设置超时么?如果必须在 win 下运行的话,有其他解决办法么?
    6 replies    2018-12-27 08:42:58 +08:00
    GoTop
        1
    GoTop  
       Dec 25, 2018
    我也遇到这个问题了,请问你解决了没?
    akmonde
        2
    akmonde  
    OP
       Dec 25, 2018
    @GoTop 在 win 下没解决,完全迁移到 linux 下了,win 下部分机制用不了。
    GoTop
        3
    GoTop  
       Dec 26, 2018
    @akmonde 如果不设置 time limit 的话,每个 task 的默认限制时长是多少秒呢
    akmonde
        4
    akmonde  
    OP
       Dec 26, 2018
    @GoTop 似乎会一直等待你跑完为止,不会限制。
    akmonde
        5
    akmonde  
    OP
       Dec 26, 2018
    @GoTop 给个笨一点的建议,如果你非要在 win 下,可以自己写时长计数,然后自己 kill 掉,不要用 celery 自带的 time limit,那玩意儿也有 bug。
    GoTop
        6
    GoTop  
       Dec 27, 2018
    @akmonde 恩,多谢,我去试试
    celery 这东西真烦啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5832 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 58ms · UTC 02:12 · PVG 10:12 · LAX 19:12 · JFK 22:12
    ♥ Do have faith in what you're doing.