【Python】Celery异步处理
参考: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安装,我用django 1.8.6和较低版本celery时候出现报错:
/usr/local/lib/python2./site-packages/Django-1.8.-py2..egg/django/core/management/base.py:: RemovedInDjango19Warning: "requires_model_validation" is deprecated in favor of "requires_system_checks".
RemovedInDjango19Warning)
如果报找不到django的错误也应该是celery装的版本不兼容导致:
[root@ /]# python manage.py
Traceback (most recent call last):
File "manage.py", line , in <module>
execute_from_command_line(sys.argv)
File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line , in execute_from_command_line
utility.execute()
File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line , in execute
django.setup()
File "/usr/lib64/python2.7/site-packages/django/__init__.py", line , in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/lib64/python2.7/site-packages/django/apps/registry.py", line , in populate
app_config = AppConfig.create(entry)
File "/usr/lib64/python2.7/site-packages/django/apps/config.py", line , in create
import_module(entry)
File "/usr/lib64/python2.7/importlib/__init__.py", line , in import_module
__import__(name)
ImportError: No module named django
建议:pip install celery==3.1.25 django-celery==3.2.2 kombu amqp django==1.11.13
所有包pip安装最新版后解决,不过django升级后会有部分低版本语法兼容问题。
在使用celery时发现几个注意点:
1、异步功能方法必须放在tasks.py中
2、异步方法不能封装在类中
启动worker时提示不可以超管用户启动worker,可以设置:
[root@test project]# python manager.py celery worker -l info
Running a worker with superuser privileges when the
worker accepts messages serialized with pickle is a very bad idea! If you really want to continue then you have to set the C_FORCE_ROOT
environment variable (but please think about this before you do). User information: uid= euid= gid= egid=0
[root@test /data]# export C_FORCE_ROOT="true"
定时方法
打开django管理界面/admin/djcelery/periodictask/可以直接设置
使用python manage.py celery beat开启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
【Python】Celery异步处理的更多相关文章
- python—Celery异步分布式
python—Celery异步分布式 Celery 是一个python开发的异步分布式任务调度模块,是一个消息传输的中间件,可以理解为一个邮箱,每当应用程序调用celery的异步任务时,会向brok ...
- python celery 异步学习
1.运行redis 2.安装celery:pip install celery[redis] 3.vim task.py import time from celery import Celery b ...
- Python开发异步任务Celery的使用教程!
1. 生产者消费者设计模式 最常用的解耦方式之一,寻找中间人(broker)搭桥,保证两个业务没有直接关联.我们称这一解耦方式为:生产者消费者设计模式 2.中间人broker 示例:此处演示Redis ...
- Django使用Celery异步任务队列
1 Celery简介 Celery是异步任务队列,可以独立于主进程运行,在主进程退出后,也不影响队列中的任务执行. 任务执行异常退出,重新启动后,会继续执行队列中的其他任务,同时可以缓存停止期间接收 ...
- Celery 异步任务 , 定时任务 , 周期任务 的芹菜
1.什么是Celery?Celery 是芹菜Celery 是基于Python实现的模块, 用于执行异步定时周期任务的其结构的组成是由 1.用户任务 app 2.管道 broker 用于存储 ...
- Django --- celery异步任务与RabbitMQ模块
一 RabbitMQ 和 celery 1 celery Celery 是一个 基于python开发的分布式异步消息任务队列,通过它可以轻松的实现任务的异步处理, 如果你的业务场景中需要用到异步任务, ...
- celery异步任务、定时任务
阅读目录 一 什么是Celery? 二 Celery的使用场景 三 Celery的安装配置 四 Celery异步任务 五Celery定时任务 六在Django中使用Celery 一 什么是Cele ...
- celery异步发送邮件
利用Django框架发送邮件的详细过程,在前两天的博客中有所记录,但是单纯的那样发邮件是有非常大的问题的,这就需要celery异步发送来解决 首先我们来看一下邮件发送的过程: Django网站先发送到 ...
- Celery - 异步任务 , 定时任务 , 周期任务
1.什么是Celery?Celery 是芹菜Celery 是基于Python实现的模块, 用于执行异步定时周期任务的其结构的组成是由 1.用户任务 app 2.管道 broker 用于存储 ...
- Celery异步处理
1.Celery概述 1.1问题抛出 我们在做网站后端程序开发时,会碰到这样的需求:用户需要在我们的网站填写注册信息,我们发给用户一封注册激活邮件到用户邮箱,如果由于各种原因,这封邮件发送所需时间较长 ...
随机推荐
- Chapter 4: Troubleshoot and debug web applications
Prevent and troubleshoot runtime issues Troubleshooting performance, security and errors using perfo ...
- StackGAN: Text to Photo-realistic Image Synthesis with Stacked Generative Adversarial Networks 论文笔记
StackGAN: Text to Photo-realistic Image Synthesis with Stacked Generative Adversarial Networks 本文将利 ...
- Linux-TCP Queue的一些问题
先来回顾下三次握手里面涉及到的问题:1. 当 client 通过 connect 向 server 发出 SYN 包时,client 会维护一个 socket 等待队列,而 server 会维护一个 ...
- div模态层示例
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- UML基础与Rose建模实训教程
目 录 第1章 初识UML. 1 1.1 初识UML用例图... 1 1.2 初识UML类图... 3 第2章 Rational Rose工具... 6 2.1 安装与配置Rational Ro ...
- spring mvc fastJson 自定义类型转换(返回数据) 实现对ObjectId类型转换
json用的alibaba fastJson ValueFilter filter = new ValueFilter() { @Override public Object process(Obje ...
- nodemon配置文件简单整理
文件名称nodemon.json 内容如下: { "restartable":"rs",//重启的命令,默认是 rs "ignore":[& ...
- 处理大并发之五 使用libevent利器bufferevent
转自:http://blog.csdn.net/feitianxuxue/article/details/9386843 处理大并发之五 使用libevent利器bufferevent 首先来翻译一段 ...
- DBMS_OUTPUT in SQL Developer
I fell sad for all the programmers(including) that has to SQL Developer as sql IDE. However, if you ...
- aspx aspx.cs
http://www.cnblogs.com/axzxs2001/archive/2009/01/19/1378383.html