-A代表APP

celery -A tasks  worker --loglevel=info -n nodemaster

 -------------- celery@nodemaster v4.1.0 (latentcall)
---- **** -----
--- * *** * -- Darwin-17.3.0-x86_64-i386-64bit 2018-04-15 11:53:09
-- * - **** ---
- ** ---------- [config]
- ** ---------- .> app: tasks:0x110b42400
- ** ---------- .> transport: redis://localhost:6379/0
- ** ---------- .> results: disabled://
- *** --- * --- .> concurrency: 4 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** -----
-------------- [queues]
.> celery exchange=celery(direct) key=celery [tasks]
. tasks.sendmail [2018-04-15 11:53:09,217: INFO/MainProcess] Connected to redis://localhost:6379/0
[2018-04-15 11:53:09,228: INFO/MainProcess] mingle: searching for neighbors
[2018-04-15 11:53:10,256: INFO/MainProcess] mingle: sync with 2 nodes
[2018-04-15 11:53:10,257: INFO/MainProcess] mingle: sync complete
[2018-04-15 11:53:10,270: INFO/MainProcess] celery@nodemaster ready. celery -A tasks inspect registered celery -A tasks inspect registered
-> celery@node2: OK
* tasks.sendmail
-> celery@nodemaster: OK
* tasks.sendmail Python 3.4.3 (default, Nov 6 2015, 22:26:48)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from tasks import sendmail
>>> sendmail.delay(dict(to='[email protected]'))
<AsyncResult: b49534cd-472f-42da-934c-057e53e0d0a8>
>>> sendmail.delay(dict(to='[email protected]'))
<AsyncResult: 99cd7565-612a-4b31-b025-de7b5c48673c>
>>> sendmail.delay(dict(to='[email protected]'))
<AsyncResult: bd123165-d220-4552-bcb8-e009c76258d7>
>>> sendmail.delay(dict(to='[email protected]'))
<AsyncResult: 01a8ef22-149c-4b24-8d92-f07468598646>
>>> sendmail.delay(dict(to='[email protected]'))
<AsyncResult: e3b50542-d643-4b4c-bd71-5fb11d7915b7>
>>> sendmail.delay(dict(to='[email protected]'))
<AsyncResult: ee225dd3-dea5-4013-907d-3dca5089c669>
>>> sendmail.delay(dict(to='[email protected]'))
<AsyncResult: e13d9de4-cd71-4aef-bc2c-bc4cc7dc3002>
>>> sendmail.delay(dict(to='[email protected]'))
<AsyncResult: 75a8c645-237c-4b64-831f-37936f71191f>
>>>

  

# tasks.py
import time
from celery import Celery celery = Celery('tasks', broker='redis://localhost:6379/0') @celery.task
def sendmail(mail):
print('....sending mail to %s...' % mail['to'])
time.sleep(20.0)
print('mail sent.')
~
05-11 17:48