日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python celery异步_【Python】Celery异步处理

發布時間:2024/9/15 python 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python celery异步_【Python】Celery异步处理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

django、celery、django-celery、kombu、amqp最好統一pip安裝,我用django 1.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" is deprecated in favor of "requires_system_checks".

RemovedInDjango19Warning)

如果報找不到django的錯誤也應該是celery裝的版本不兼容導致:

[root@1 /]# python manage.py

Traceback (most recent call last):

File"manage.py", line 22, in execute_from_command_line(sys.argv)

File"/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 364, inexecute_from_command_line

utility.execute()

File"/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 338, inexecute

django.setup()

File"/usr/lib64/python2.7/site-packages/django/__init__.py", line 27, insetup

apps.populate(settings.INSTALLED_APPS)

File"/usr/lib64/python2.7/site-packages/django/apps/registry.py", line 85, inpopulate

app_config=AppConfig.create(entry)

File"/usr/lib64/python2.7/site-packages/django/apps/config.py", line 127, increate

import_module(entry)

File"/usr/lib64/python2.7/importlib/__init__.py", line 37, inimport_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 infoRunning a worker with superuser privileges when the

worker accepts messages serialized with pickle is a very bad idea!If you really want to continuethenyou have to set the C_FORCE_ROOT

environment variable (but please think about this before youdo).

User information: uid=0 euid=0 gid=0 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秒執行多次

異步操作

redis存儲python對象使用pickle模塊

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的python celery异步_【Python】Celery异步处理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。