Django 项目中 Celery task Debug 调试

celery debug 调试直接用django 不是很方便

可以采用 pdb 的形式进行调试,在celery 中她对 pdb 做了一次的封装,变成了rdb

引入rdb

Python
from <span class="wp_keywordlink_affiliate"><a href="https://www.168seo.cn/tag/celery" title="View all posts in celery" target="_blank">celery</a></span>.contrib import <span class="wp_keywordlink_affiliate"><a href="https://www.168seo.cn/tag/rdb" title="View all posts in rdb" target="_blank">rdb</a></span> #引入包 rdb.set_trace() # 设置断点
1
2
3
4
from celery . contrib import rdb #引入包
 
rdb . set_trace ( ) # 设置断点
 

启动django

Python
Django version 2.1.4, using settings 'taskproj.settings' Development server is running at http://[127.0.0.1]:8000/ Using the Werkzeug debugger (http://werkzeug.pocoo.org/) Quit the server with CONTROL-C. * Debugger is active! * Debugger PIN: 329-253-017 127.0.0.1 - - [03/Jul/2019 16:36:03] "POST /start_task/ HTTP/1.1" 200 -
1
2
3
4
5
6
7
8
Django version 2.1.4 , using settings 'taskproj.settings'
Development server is running at http : / / [ 127.0.0.1 ] : 8000 /
Using the Werkzeug debugger ( http : / / werkzeug . pocoo . org / )
Quit the server with CONTROL - C .
* Debugger is active !
* Debugger PIN : 329 - 253 - 017
127.0.0.1 - - [ 03 / Jul / 2019 16 : 36 : 03 ] "POST /start_task/ HTTP/1.1" 200 -
 

启动worker

Python
. app01.tasks.add . app01.tasks.get_url . app01.tasks.mul . app01.utils.tasks.C . app01.utils.tasks.extract_data . app01.utils.tasks.extract_urls . app01.utils.tasks.get_contents . app01.utils.tasks.parser . app01.utils.tasks.xpath_extract_urls . celery.accumulate . celery.backend_cleanup . celery.chain . celery.chord . celery.chord_unlock . celery.chunks . celery.group . celery.map . celery.starmap . taskproj.celery.debug_task
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
   . app01 . tasks . add
   . app01 . tasks . get _url
   . app01 . tasks . mul
   . app01 . utils . tasks . C
   . app01 . utils . tasks . extract _data
   . app01 . utils . tasks . extract _urls
   . app01 . utils . tasks . get _contents
   . app01 . utils . tasks . parser
   . app01 . utils . tasks . xpath_extract _urls
   . celery . accumulate
   . celery . backend _cleanup
   . celery . chain
   . celery . chord
   . celery . chord _unlock
   . celery . chunks
   . celery . group
   . celery . map
   . celery . starmap
   . taskproj . celery . debug _task
 
 

发送生产者

Python
<span class="wp_keywordlink"><a href="http://www.168seo.cn/python" title="python">python</a></span> post_data.py
1
2
python post_data . py
 

观察worker

Python
-de13-4aca-8cb9-22f32ea5d00f', 'shadow': None, 'eta': None, 'expires': None, 'group': None, 'retries': 0, 'timelimit': [None, None], 'root_id': '8461613f-18ab-4756-8fff-e56c164613b1', 'parent_ id': '8461613f-18ab-4756-8fff-e56c164613b1', 'argsrepr': "(['https://www.csai.cn/gonglue/', 'https://www.csai.cn/pingce/', 'https://jin.baidu.com/article', 'https://jin.baidu.com/article/car', 'https://jin.baidu.com/article/list_120 000', 'https://jin.baidu.com/article/list_160000'],)", 'kwargsrepr': '{}', 'origin': 'gen15574@songhao-pc', 'reply_to': 'd9fda1c9-044d-38e5-b640-d7f418f525b3', 'correlation_id': '7515aa8e-de13-4aca-8cb9-22f32ea5d00f', 'delivery_info ': {'exchange': '', 'routing_key': 'celery', 'priority': 0, 'redelivered': False}}, '[[["https://www.csai.cn/gonglue/", "https://www.csai.cn/pingce/", "https://jin.baidu.com/article",... kwargs:{}) [2019-07-04 09:18:46,773: DEBUG/MainProcess] Task accepted: app01.utils.tasks.xpath_extract_urls[7515aa8e-de13-4aca-8cb9-22f32ea5d00f] pid:15575 [2019-07-04 09:18:46,776: WARNING/ForkPoolWorker-2] Remote Debugger:6901: Ready to connect: telnet 127.0.0.1 6901 Type `exit` in session to continue. Remote Debugger:6901: Waiting for client... # 监听的是 6901
1
2
3
4
5
6
7
8
9
10
11
- de13 - 4aca - 8cb9 - 22f32ea5d00f ', ' shadow ': None, ' eta ': None, ' expires ': None, ' group ': None, ' retries ': 0, ' timelimit ': [None, None], ' root _id ': ' 8461613f - 18ab - 4756 - 8fff - e56c164613b1 ', ' parent_
id ': ' 8461613f - 18ab - 4756 - 8fff - e56c164613b1 ', ' argsrepr ': "([' https : / / www . csai . cn / gonglue / ', ' https : / / www . csai . cn / pingce / ', ' https : / / jin . baidu . com / article ', ' https : / / jin . baidu . com / article / car ', ' https : / / jin . baidu . com / article / list _120
000 ', ' https : / / jin . baidu . com / article / list _160000 '],)", ' kwargsrepr ': ' { } ', ' origin ': ' gen15574 @ songhao - pc ', ' reply _to ': ' d9fda1c9 - 044d - 38e5 - b640 - d7f418f525b3 ', ' correlation _id ': ' 7515aa8e - de13 - 4aca - 8cb9 - 22f32ea5d00f ', ' delivery _info
': {' exchange ': ' ', ' routing _key ': ' celery ', ' priority ': 0, ' redelivered ': False}}, ' [ [ [ "https://www.csai.cn/gonglue/" , "https://www.csai.cn/pingce/" , "https://jin.baidu.com/article" , . . . kwargs : { } )
[ 2019 - 07 - 04 09 : 18 : 46 , 773 : DEBUG / MainProcess ] Task accepted : app01 . utils . tasks . xpath_extract_urls [ 7515aa8e - de13 - 4aca - 8cb9 - 22f32ea5d00f ] pid : 15575
[ 2019 - 07 - 04 09 : 18 : 46 , 776 : WARNING / ForkPoolWorker - 2 ] Remote Debugger : 6901 : Ready to connect : telnet 127.0.0.1 6901
 
Type ` exit ` in session to continue .
 
Remote Debugger : 6901 : Waiting for client . . . # 监听的是 6901
 

打开监听端口 进行调试

rdb 调试操作



  • zeropython 微信公众号 5868037 QQ号 5868037@qq.com QQ邮箱
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值