celery安裝

使用celery最好使用3.7一下的版本,因?yàn)閍sync關(guān)鍵字的緣故,會(huì)報(bào)以下的錯(cuò)誤。

Traceback (most recent call last):

? File "/Library/Frameworks/Python.framework/Versions/3.7/bin/celery", line 11, in <module>

? ? sys.exit(main())

? File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/__main__.py", line 30, in main

? ? main()

? File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/celery.py", line 81, in main

? ? cmd.execute_from_commandline(argv)

? File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/celery.py", line 793, in execute_from_commandline

? ? super(CeleryCommand, self).execute_from_commandline(argv)))

? File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/base.py", line 311, in execute_from_commandline

? ? return self.handle_argv(self.prog_name, argv[1:])

? File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/celery.py", line 785, in handle_argv

? ? return self.execute(command, argv)

? File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/celery.py", line 717, in execute

? ? ).run_from_argv(self.prog_name, argv[1:], command=argv[0])

? File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/worker.py", line 179, in run_from_argv

? ? return self(*args, **options)

? File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/base.py", line 274, in __call__

? ? ret = self.run(*args, **kwargs)

? File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/worker.py", line 194, in run

? ? pool_cls = (concurrency.get_implementation(pool_cls) or

? File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/concurrency/__init__.py", line 29, in get_implementation

? ? return symbol_by_name(cls, ALIASES)

? File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/kombu/utils/__init__.py", line 96, in symbol_by_name

? ? module = imp(module_name, package=package, **kwargs)

? File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module

? ? return _bootstrap._gcd_import(name[level:], package, level)

? File "<frozen importlib._bootstrap>", line 1006, in _gcd_import

? File "<frozen importlib._bootstrap>", line 983, in _find_and_load

? File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked

? File "<frozen importlib._bootstrap>", line 677, in _load_unlocked

? File "<frozen importlib._bootstrap_external>", line 728, in exec_module

? File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed

? File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/concurrency/prefork.py", line 20, in <module>

? ? from celery.concurrency.base import BasePool

? File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/concurrency/base.py", line 21, in <module>

? ? from celery.utils import timer2

? File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/utils/timer2.py", line 19

? ? from kombu.async.timer import Entry, Timer as Schedule, to_timestamp, logger

? ? ? ? ? ? ? ? ? ^

SyntaxError: invalid syntax

安裝:

pip install -U Celery

依賴(lài)綁定:

pip install celery[librabbitmq]

pip install celery[librabbitmq,redis,auth,msgpack]

使用:

from celery import Celery

# 我們這里案例使用redis作為broker

app = Celery('demo', broker='redis://:332572@127.0.0.1/1')

# 創(chuàng)建任務(wù)函數(shù)

@app.task

def my_task():

? ? print("任務(wù)函數(shù)正在執(zhí)行....")

運(yùn)行:

celery -A tasks worker --loglevel=info

4.0以上的版本的celery運(yùn)行下來(lái)可能會(huì)報(bào)錯(cuò):

[2018-01-12 19:08:15,545: INFO/MainProcess] Received task: tasks.add[5d387722-5389-441b-9b01-a619b93b4702]

[2018-01-12 19:08:15,550: ERROR/MainProcess] Task handler raised error: ValueError('not enough values to unpack (expected 3, got 0)',)

Traceback (most recent call last):

? File "d:\programmingsoftware\python35\lib\site-packages\billiard\pool.py", line 358, in workloop

? ? result = (True, prepare_result(fun(*args, **kwargs)))

? File "d:\programmingsoftware\python35\lib\site-packages\celery\app\trace.py", line 525, in _fast_trace_task

? ? tasks, accept, hostname = _loc

ValueError: not enough values to unpack (expected 3, got 0)

解決:(參考)

先安裝一個(gè)eventlet

pip install eventlet

然后啟動(dòng)worker的時(shí)候加一個(gè)參數(shù),如下:

celery -A <mymodule> worker --loglevel=info -P eventlet

使用:

進(jìn)入ipython


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 安裝RabbitMQ,會(huì)提示安裝Erlang,按照提示即可。 確認(rèn)RabbitMQ是否安裝成功。a. 啟動(dòng)Rabb...
    panda1987閱讀 7,588評(píng)論 1 1
  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom閱讀 3,219評(píng)論 0 3
  • # Awesome Python [![Awesome](https://cdn.rawgit.com/sindr...
    emily_007閱讀 2,343評(píng)論 0 3
  • 題目1: DOM0 事件和DOM2級(jí)在事件監(jiān)聽(tīng)使用方式上有什么區(qū)別? DOM0級(jí)事件處理方式:通過(guò)JavaScri...
    輝夜乀閱讀 326評(píng)論 0 0
  • 深夜寫(xiě)在紙上的文字已經(jīng)昏昏入睡 就如同初見(jiàn)你時(shí)在寫(xiě)著一年的文字識(shí)的清風(fēng),字里有雨 年月布滿了整個(gè)星空風(fēng)吹走了所有的...
    摘星辰丶閱讀 1,463評(píng)論 14 43

友情鏈接更多精彩內(nèi)容