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

请问有大佬知道怎么用 pycharm 调试 celery 吗?

  •  
  •   darksand · May 30, 2018 · 8514 views
    This topic created in 2908 days ago, the information mentioned may be changed or developed.

    我想调试 worker 里面的任务,找了好久还是没有找到办法。。有大佬知道么。。

    30 replies    2020-05-22 11:49:11 +08:00
    rogwan
        1
    rogwan  
       May 30, 2018 via Android
    和单独启动一个 App 没区别,直接在 pycharm 命令行中启动 celery 就可以
    darksand
        2
    darksand  
    OP
       May 30, 2018
    @rogwan 请问具体怎么启动呢。。大佬谢谢
    darksand
        3
    darksand  
    OP
       May 30, 2018
    @rogwan 我在 pycharm 中启动了 worker 但是怎么打断点调试呢。。
    misaka19000
        4
    misaka19000  
       May 30, 2018
    在右上角的 edit configurations 里面应该可以设置程序的启动方式吧,在里面设置好启动 celery 的命令然后使用 pycharm 来启动应用应该就可以了
    darksand
        5
    darksand  
    OP
       May 30, 2018
    @misaka19000 我尝试过你说的方法 但是在 [Script] 那个位置 我不知道怎么写,我找不到启动 worker 的脚本
    qi1070445109
        6
    qi1070445109  
       May 30, 2018 via Android
    @darksand 你把命令写脚本里不就行了?😥
    darksand
        7
    darksand  
    OP
       May 30, 2018
    @qi1070445109 不行


    Connected to pydev debugger (build 145.971)
    Traceback (most recent call last):
    File "C:\Program Files (x86)\JetBrains\PyCharm 2016.1.3\helpers\pydev\pydevd.py", line 1531, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
    File "C:\Program Files (x86)\JetBrains\PyCharm 2016.1.3\helpers\pydev\pydevd.py", line 938, in run
    pydev_imports.execfile(file, globals, locals) # execute the script
    IOError: [Errno 2] No such file or directory: 'celery -A ics.task.example.baidu_news_task worker -E -Q baidu_news_queue -n baidu_news.%h -l info'

    Process finished with exit code 1
    darksand
        8
    darksand  
    OP
       May 30, 2018
    @qi1070445109 这个位置 必须是一个脚本吧。。
    wcsjtu
        9
    wcsjtu  
       May 30, 2018 via Android
    celery 有多线程模式的,比多进程调试要方便很多
    qi1070445109
        10
    qi1070445109  
       May 30, 2018 via Android
    @darksand 是这样,那个位置就是个 py 文件,然后你把用 os 来执行 celery 的启动命令。
    darksand
        11
    darksand  
    OP
       May 30, 2018
    @qi1070445109 我试了 不行啊 进不了断点
    suber
        12
    suber  
       May 30, 2018
    你调试的时候,把并发方式设置为 solo
    https://github.com/celery/celery/blob/master/celery/concurrency/solo.py
    suber
        13
    suber  
       May 30, 2018
    @darksand #7,你这个报错,如果是在 Linux 下,用 celery 命令所在的全路径。如:`/usr/local/bin/celery`
    darksand
        14
    darksand  
    OP
       May 30, 2018
    @suber 我现在是在 windows 我找到了 celery.exe 那个地方我填写 E:\Python27\Scripts\celery.exe
    但是还是不行
    yongzhong
        15
    yongzhong  
       May 30, 2018   ❤️ 1
    darksand
        16
    darksand  
    OP
       May 30, 2018
    @suber
    Connected to pydev debugger (build 145.971)
    Traceback (most recent call last):
    File "C:\Program Files (x86)\JetBrains\PyCharm 2016.1.3\helpers\pydev\pydevd.py", line 1531, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
    File "C:\Program Files (x86)\JetBrains\PyCharm 2016.1.3\helpers\pydev\pydevd.py", line 938, in run
    pydev_imports.execfile(file, globals, locals) # execute the script
    File "E:/Python27/Scripts/celery.exe", line 1
    SyntaxError: Non-ASCII character '\x90' in file E:/Python27/Scripts/celery.exe on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

    Process finished with exit code 1

    这个错。。意思这个还必须是个脚本。。exe 不行
    darksand
        17
    darksand  
    OP
       May 30, 2018
    @yongzhong 兄弟 我的是 windows。。
    suber
        18
    suber  
       May 30, 2018
    接#12,默认的多进程调试也是可以的。但是如果一次发多个任务,每个任务都要调试的话,需要在 pycharm 里面手动找到接收了任务的进程,然后切换并调试。
    suber
        19
    suber  
       May 30, 2018
    @darksand 你 windows,应该是 exe 就可以了。你截图一下调试的配置
    darksand
        20
    darksand  
    OP
       May 30, 2018
    @suber 恩 明白,但是我现在不知道如何调试。。大佬能给仔细说说吗 谢谢!
    我是 windows 没有 /usr/local/bin/celery 只有 E:\Python27\Scripts\celery.exe
    darksand
        21
    darksand  
    OP
       May 30, 2018
    @suber
    [Script] E:\Python27\Scripts\celery.exe
    [Script parameters] -A ics.task.example.baidu_news_task worker -E -Q baidu_news_queue -n baidu_news.%h -l info
    suber
        22
    suber  
       May 30, 2018
    看你的#16 报错,pycharm 解析路径的时候有点问题。
    两种方法试一下。1, 不直接填写 celery 路径,用后面的按钮,直接选择你对应路径下的 celery ; 2, 把这个路径配置到你的 windows 环境变量中,然后 script 那里直接填 celery。
    qdzzyb
        23
    qdzzyb  
       May 30, 2018
    换个思路, 可以直接在解释器里同步调用任务就可以了,断点用 ipdb 好了
    darksand
        24
    darksand  
    OP
       May 30, 2018
    谢谢大家,已经找到在 window 下面的解决办法了
    https://www.e-learn.cn/content/wangluowenzhang/342882
    windows 下不支持楼上说的方法来调试
    所以采用曲线救国 使用 django 的 manage.py 来启动 worker 就可以调试了!!!
    dishonest
        25
    dishonest  
       May 30, 2018
    我记得 celery 已经放弃支持 windows,LZ 有大概率会碰到无法解释的 bug
    tonghuashuai
        26
    tonghuashuai  
       May 30, 2018
    print 大法好
    bilibalao
        27
    bilibalao  
       May 31, 2018
    celery flower -A xxx --broker=redis://127.0.0.1:6379 你先 terminal 连 redis,
    然后 terminal 起一个 worker celery -A xxx worker --loglevel=info, 然后正常打断点开 debug 模式调试就行了
    param
        28
    param  
       May 31, 2018 via Android
    @darksand 你用 Windows ? celery 4.x 新版已经不支持 Windows。Linux 的话,pycharm 直接用 celery 的启动入口来启动是可以断电调试的,但如果 Windows 是 celery.exe 的这种二进制的话,我就不懂了。
    haotianseo
        29
    haotianseo  
       Jul 4, 2019
    Celery Debug 采用 rdb 形式,方便快捷

    https://www.168seo.cn/python-2/25027.html
    evaseemefly
        30
    evaseemefly  
       May 22, 2020
    mac 可以调试,win 下面目前还是无法调试
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3078 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 53ms · UTC 13:54 · PVG 21:54 · LAX 06:54 · JFK 09:54
    ♥ Do have faith in what you're doing.