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

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

  •  
  •   darksand · 2018-05-30 12:31:03 +08:00 · 7273 次点击
    这是一个创建于 2129 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    30 条回复    2020-05-22 11:49:11 +08:00
    rogwan
        1
    rogwan  
       2018-05-30 12:37:37 +08:00 via Android
    和单独启动一个 App 没区别,直接在 pycharm 命令行中启动 celery 就可以
    darksand
        2
    darksand  
    OP
       2018-05-30 12:44:53 +08:00
    @rogwan 请问具体怎么启动呢。。大佬谢谢
    darksand
        3
    darksand  
    OP
       2018-05-30 12:52:07 +08:00
    @rogwan 我在 pycharm 中启动了 worker 但是怎么打断点调试呢。。
    misaka19000
        4
    misaka19000  
       2018-05-30 12:52:43 +08:00
    在右上角的 edit configurations 里面应该可以设置程序的启动方式吧,在里面设置好启动 celery 的命令然后使用 pycharm 来启动应用应该就可以了
    darksand
        5
    darksand  
    OP
       2018-05-30 12:55:31 +08:00
    @misaka19000 我尝试过你说的方法 但是在 [Script] 那个位置 我不知道怎么写,我找不到启动 worker 的脚本
    qi1070445109
        6
    qi1070445109  
       2018-05-30 12:57:48 +08:00 via Android
    @darksand 你把命令写脚本里不就行了?😥
    darksand
        7
    darksand  
    OP
       2018-05-30 12:59:19 +08:00
    @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
       2018-05-30 12:59:47 +08:00
    @qi1070445109 这个位置 必须是一个脚本吧。。
    wcsjtu
        9
    wcsjtu  
       2018-05-30 13:02:50 +08:00 via Android
    celery 有多线程模式的,比多进程调试要方便很多
    qi1070445109
        10
    qi1070445109  
       2018-05-30 13:10:29 +08:00 via Android
    @darksand 是这样,那个位置就是个 py 文件,然后你把用 os 来执行 celery 的启动命令。
    darksand
        11
    darksand  
    OP
       2018-05-30 13:30:08 +08:00
    @qi1070445109 我试了 不行啊 进不了断点
    suber
        12
    suber  
       2018-05-30 13:35:10 +08:00
    你调试的时候,把并发方式设置为 solo
    https://github.com/celery/celery/blob/master/celery/concurrency/solo.py
    suber
        13
    suber  
       2018-05-30 13:39:03 +08:00
    @darksand #7,你这个报错,如果是在 Linux 下,用 celery 命令所在的全路径。如:`/usr/local/bin/celery`
    darksand
        14
    darksand  
    OP
       2018-05-30 13:43:01 +08:00
    @suber 我现在是在 windows 我找到了 celery.exe 那个地方我填写 E:\Python27\Scripts\celery.exe
    但是还是不行
    yongzhong
        15
    yongzhong  
       2018-05-30 13:43:07 +08:00   ❤️ 1
    darksand
        16
    darksand  
    OP
       2018-05-30 13:44:34 +08:00
    @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
       2018-05-30 13:45:40 +08:00
    @yongzhong 兄弟 我的是 windows。。
    suber
        18
    suber  
       2018-05-30 13:46:03 +08:00
    接#12,默认的多进程调试也是可以的。但是如果一次发多个任务,每个任务都要调试的话,需要在 pycharm 里面手动找到接收了任务的进程,然后切换并调试。
    suber
        19
    suber  
       2018-05-30 13:47:58 +08:00
    @darksand 你 windows,应该是 exe 就可以了。你截图一下调试的配置
    darksand
        20
    darksand  
    OP
       2018-05-30 13:48:50 +08:00
    @suber 恩 明白,但是我现在不知道如何调试。。大佬能给仔细说说吗 谢谢!
    我是 windows 没有 /usr/local/bin/celery 只有 E:\Python27\Scripts\celery.exe
    darksand
        21
    darksand  
    OP
       2018-05-30 13:53:12 +08:00
    @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  
       2018-05-30 14:43:46 +08:00
    看你的#16 报错,pycharm 解析路径的时候有点问题。
    两种方法试一下。1, 不直接填写 celery 路径,用后面的按钮,直接选择你对应路径下的 celery ; 2, 把这个路径配置到你的 windows 环境变量中,然后 script 那里直接填 celery。
    qdzzyb
        23
    qdzzyb  
       2018-05-30 14:50:37 +08:00
    换个思路, 可以直接在解释器里同步调用任务就可以了,断点用 ipdb 好了
    darksand
        24
    darksand  
    OP
       2018-05-30 15:34:09 +08:00
    谢谢大家,已经找到在 window 下面的解决办法了
    https://www.e-learn.cn/content/wangluowenzhang/342882
    windows 下不支持楼上说的方法来调试
    所以采用曲线救国 使用 django 的 manage.py 来启动 worker 就可以调试了!!!
    dishonest
        25
    dishonest  
       2018-05-30 17:32:58 +08:00
    我记得 celery 已经放弃支持 windows,LZ 有大概率会碰到无法解释的 bug
    tonghuashuai
        26
    tonghuashuai  
       2018-05-30 19:03:00 +08:00
    print 大法好
    bilibalao
        27
    bilibalao  
       2018-05-31 00:43:52 +08:00
    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  
       2018-05-31 01:45:36 +08:00 via Android
    @darksand 你用 Windows ? celery 4.x 新版已经不支持 Windows。Linux 的话,pycharm 直接用 celery 的启动入口来启动是可以断电调试的,但如果 Windows 是 celery.exe 的这种二进制的话,我就不懂了。
    haotianseo
        29
    haotianseo  
       2019-07-04 09:38:02 +08:00
    Celery Debug 采用 rdb 形式,方便快捷

    https://www.168seo.cn/python-2/25027.html
    evaseemefly
        30
    evaseemefly  
       2020-05-22 11:49:11 +08:00
    mac 可以调试,win 下面目前还是无法调试
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1531 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 17:08 · PVG 01:08 · LAX 10:08 · JFK 13:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.