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

celery 中如何停止子进程

  •  
  •   u2gign · Jul 20, 2022 · 3388 views
    This topic created in 1418 days ago, the information mentioned may be changed or developed.
    app.control.revoke(task_id, terminate=True, signal="SIGKILL")
    

    用上面的方法发现停止进程后,子进程并不会被杀掉。 难道需要收集所有子进程,然后在循环杀掉吗?不知道是否有更好的方法

    7 replies    2022-07-29 13:28:41 +08:00
    u2gign
        1
    u2gign  
    OP
       Jul 20, 2022
    prctl(PR_SET_PDEATHSIG, SIGKILL)
    找到一个这个方法
    hanssx
        2
    hanssx  
       Jul 20, 2022   ❤️ 1
    在 celery 中启用的子进程,最好要设置进程组 setpgrp ,kill 的时候会一块 kill 掉,比如 subprocess.Popen()这个所启用的,参考 https://www.jianshu.com/p/8e582146bd4c

    另外可以发送 SIG_USR 信号,参考 https://stackoverflow.com/questions/8920643/cancel-an-already-executing-task-with-celery/29627549#29627549

    再看一下这个 https://docs.celeryq.dev/en/latest/userguide/workers.html#worker-persistent-revokes

    而且我这边之前测试 celery revoke 有一定机率会 kill celery worker 进程,感觉 celery 很多 bug 没修,现在不清楚了,后来换了 dramatiq
    u2gign
        3
    u2gign  
    OP
       Jul 20, 2022
    @hanssx 非常感谢
    among
        4
    among  
       Jul 20, 2022
    @hanssx

    dramatiq 用起来怎么样,现在用 celery ,是感觉到有很多问题。
    hanssx
        5
    hanssx  
       Jul 20, 2022
    @among 不好意思,这块可能给不了啥意见,我只能说可以先弄个 Demo 试试,不要直接上生产,特性没 celery 多,但是足够我用而且没有遇到啥 BUG ,一年前用过一段时间,可能参考意义不大,我当时用的时候版本都偏低了,反正让我现在做项目选,我会先试 dramatiq 。
    cpyS963ga8s46yV5
        6
    cpyS963ga8s46yV5  
       Jul 22, 2022
    @hanssx 第三个链接,永久 revoke 有试过吗?设置 statedb 参数会不会让 task_id 一直增多然后在内存占用大,因为从说明来看是通过这个文件持久化,重启的时候加载进内存,但是并没有说这个文件存的是多长时间的 revoke 的 task 。
    chioplkijhman
        7
    chioplkijhman  
       Jul 29, 2022
    我的 ffmpeg 任务需要先 revoke ,再用 psutil kill 。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2860 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 56ms · UTC 02:52 · PVG 10:52 · LAX 19:52 · JFK 22:52
    ♥ Do have faith in what you're doing.