当前位置:网站首页>Cell asynchronously invokes method change records
Cell asynchronously invokes method change records
2022-06-10 14:13:00 【tnan2522】
Celery It's a task queue , You can handle... Asynchronously
stay 4.0 After version python Use celery There will be mistakes , At this point you need to install eventlet modular
pip install eventlet
The default is
celery -A task worker --loglevel=info
start-up celery
4.0 Post start celery:
celery -A task worker --loglevel=info -P eventlet
stay work The decorator also needs to be changed
The default is :
import time
from celery import Celery
app = Celery(
broker='amqp://[email protected]//', # Message queue url
backend='redis://localhost:6379/9' # Store the result of the call in Redis in
)
@app.task
def add(x, y):
print("celery The data received is : ", x, y)
print("x+y=", x+y)
# time.sleep(100)
return x + y
Change it to :
import time
from celery import Celery
app = Celery(
broker='amqp://[email protected]//', # Message queue url
backend='redis://localhost:6379/9' # Store the result of the call in Redis in
)
@app.task(name="aaabbb")
def add(x, y):
print("celery The data received is : ", x, y)
print("x+y=", x+y)
# time.sleep(100)
return x + y
This is because if you do not set a name for the task queue , The queue will be named according to the current module name and method name , Such as aaabbb
Importing and using in other modules is , Such as
from celery_aabb.task import add
for i in range(50):
add.delay(i, i + 10)
add.delay When sending a message to a task queue, the queue sent to is celery_aabb.task.add, In this way, the corresponding task queue processing cannot be found , There will be an exception
If the queue name is set , that , In the import add I will use it when I use it celery Decorate the named name as the name of the task queue sent , Thus, the task processing queue is found
When it's called remotely ,
from celery import Celery
app = Celery(
broker='amqp://[email protected]//', # Message queue url
)
app.send_task("aabbcc", [10, 20])
Just write the name of the task queue to find celery Task queue started in
Save execution results :
backend='redis://localhost:6379/8'
Store the result of the call in Redis in , Storage format yes json Serialized string
stay add In the processing function, the return The return value is stored in as the value to be saved redis in , If there is no return value ,celery It also stores data , However, it stores the restful by null
celery Send E-mail
stay task Import other modules into the work module , Because it was started in command line mode , So it can only find the files and folders in the current directory , Can't find the files and folders on the upper level ,
You need to put the mail sending module into task Under the directory of work modules
边栏推荐
- 【笔记】C语言数组指针、结构体+二维数组指针小记
- Microsoft Word 教程,如何在 Word 中更改页边距、创建新闻稿栏?
- 北京/上海内推 | 微软亚洲研究院系统与网络组招聘全职实习生
- Ue5 how to convert screen coordinates to world coordinates and World Directions
- 【离散数学期复习系列】三、集合的概念及运算
- D:\setup Exe could not find the problem
- 【专题介绍】圆桌论坛——AI与音视频技术的融合之路
- 【笔记】74HC573的一些记录
- 2022 practice questions and online simulation test for the third batch of Guangdong Provincial Safety Officer a certificate (principal)
- What happened when the legendary login prompt failed to connect to the server? How to solve it?
猜你喜欢

CVPR 2022 | 基于序列对比学习的长视频逐帧动作表示

New features mail GPU counter module adds GPU primitive processing and GPU shader cycles

软件智能:aaas系统 度量衡及文法的形式规则

CVPR 2022 | frame by frame motion representation of long video based on sequence contrast learning

大厂必备的40个方法论

Win10 virtual machine download and installation process

Microsoft Word tutorial, how to change margins and create a newsletter column in word?

【重庆大学】初试复试资料分享(附考研群)

Flutter Listview, Column, Row学习个人总结2

UE5如何將屏幕坐標轉為世界坐標和世界方向
随机推荐
Mutual transformation among lists, arrays and tensors
短文本重复率快速检测
C multithreading learning note 1
QT将接收到的json数据(含中文)unicode转utf8
Singleton pattern and special class design
40 necessary methodologies for large factories
列表、数组和张量之间的相互转化
【C语言】指针函数与函数指针、数组函数
What does the multi cloud management platform CMP mean? Who can explain it clearly
anaconda安装opencv(cv2),在jupyter notebook中使用
[big guy show] aiops in the eyes of Borui data, choosing the right track and the right people
大厂必备的40个方法论
CVPR 2022 | 基于序列对比学习的长视频逐帧动作表示
【解决】每次加载已经训练好的模型,生成的向量会有不同
2022 Shandong Province safety officer C certificate retraining question bank and online simulation examination
Redis基本使用1
Why should the R & D effectiveness team of Internet companies be independent? When is independence?
NC|王军/宋默识结合三代测序解析肠道菌群结构变异和功能
How to locate the hot problem of the game
基于FPGA的VGA协议实现