【Python】Celery异步处理
2016-07-26 10:38
585 查看
参考:http://www.cnblogs.com/znicy/p/5626040.html
参考:http://www.weiguda.com/blog/73/
参考:http://blog.csdn.net/iloveyin/article/details/44940931
django、celery、django-celery、kombu、amqp最好统一pip安装,我用django1.8.6和较低版本celery时候出现报错:
所有包pip安装最新版后解决,不过django升级后会有部分低版本语法兼容问题。
在使用celery时发现几个注意点:
1、异步功能方法必须放在tasks.py中
2、异步方法不能封装在类中
启动worker时提示不可以超管用户启动worker,可以设置:
定时方法
打开django管理界面/admin/djcelery/periodictask/可以直接设置
使用pythonmanage.pycelerybeat开启beat服务
注意:
1、名称要和方法名对应,比如app中background的tasks中的fun_test方法,Task(registered)中选择这个方法
2、由于队列处理是每5秒,所以Interval中如果设置小于5秒会出现每5秒执行多次
异步操作
参考:http://www.cnblogs.com/ifkite/p/4257721.html
参考:http://www.cnblogs.com/lianzhilei/p/7133295.html
redis存储python对象使用pickle模块
参考:http://jingyan.baidu.com/article/a681b0de0e88003b184346b6.html
参考:
参考:
django、celery、django-celery、kombu、amqp最好统一pip安装,我用django1.8.6和较低版本celery时候出现报错:
/usr/local/lib/python2.7/site-packages/Django-1.8.6-py2.7.egg/django/core/management/base.py:260:RemovedInDjango19Warning:"requires_model_validation"isdeprecatedinfavorof"requires_system_checks". RemovedInDjango19Warning)
所有包pip安装最新版后解决,不过django升级后会有部分低版本语法兼容问题。
在使用celery时发现几个注意点:
1、异步功能方法必须放在tasks.py中
2、异步方法不能封装在类中
启动worker时提示不可以超管用户启动worker,可以设置:
[root@testproject]#pythonmanager.pyceleryworker-linfo Runningaworkerwithsuperuserprivilegeswhenthe workeracceptsmessagesserializedwithpickleisaverybadidea! IfyoureallywanttocontinuethenyouhavetosettheC_FORCE_ROOT environmentvariable(butpleasethinkaboutthisbeforeyoudo). Userinformation:uid=0euid=0gid=0egid=0
[root@test/data]#exportC_FORCE_ROOT="true"
定时方法
打开django管理界面/admin/djcelery/periodictask/可以直接设置
使用pythonmanage.pycelerybeat开启beat服务
注意:
1、名称要和方法名对应,比如app中background的tasks中的fun_test方法,Task(registered)中选择这个方法
2、由于队列处理是每5秒,所以Interval中如果设置小于5秒会出现每5秒执行多次
异步操作
参考:
参考:
redis存储python对象使用pickle模块
参考:
相关文章推荐
- Python 不能显示中文的解决办法
- Python 命令行输出的颜色设置
- 64位Win7下安装并配置Python3的深度学习库:Theano
- 【python challenge】level2
- Numpy Python
- python函数
- python学习 第四篇 函数
- Python 读取写入配置文件 —— ConfigParser
- Python新手学习基础之运算符——位运算
- Python新手学习基础之运算符——位运算
- Python和二进制(1)
- MyEclipse + Pydev开发Python时import报错解决方法
- python批量制作雷达图的实现方法
- python常见报错提示解析
- python os模块
- odoo根据模型生成security配置信息
- Python中的下划线
- python中,单下划线与双下划线的命名方式(私有和保护)
- Spark--python开发实例
- 出版商统计出最受欢迎的编程语言:Python 居首