The asynchronous task script tasks.py will be executed:
fromCeleryImportCelery fromCeleryImportGroup#host= ' 10.32.21.52 ', port=6379, db=3App = Celery ('Tasks', backend ='REDIS://10.32.21.52:6379/14', broker='REDIS://10.32.21.52:6379/15') @app. TaskdefAdd (x, y):returnX +Y@app.taskdefTsum (ITE):returnsum (ITE) @app. Task (Trail=True)defA (how_many):returnGroup (B.S (i) forIinchRange (How_many)) () @app. Task (Trail=True)defB (i):returnPow2.delay (i) @app. Task (Trail=True)defPow2 (i):returnI * * 2
Where: Celery in the app configuration, detailed configuration can refer to the document: http://docs.celeryproject.org/en/latest/getting-started/ First-steps-with-celery.html#configuration
To start a task:
Celery-a Tasks worker--loglevel=info
The output after startup, displaying the server and configuration information and task running log;
To invoke a task through a script:
fromTasksImportAdd fromTasksImportTsum fromTasksImportA fromCeleryImportChordresult= Add.delay (4, 4)~tsum.map ([Range], range (100)])~add.starmap ([item forIteminchZip (range), range (10))])#Chord (Add.s (i, I) for I in Xrange ()) (TSUM.S ()). Get ()Chord ((Add.s (i, i) forIinchXrange (100) ), TSUM.S ()) () Add.chunks (Zip (xrange (, xrange (100)), 10)()Print(result.backend)Printresult.get () result= A.delay (10)
Write the task is too simple, than a single machine is slow, only on the crawl task to try ~
Celery uses the adorner to abstract each task into a plug-in dispatch that sends a message to a third party, such as Redis, and then assigns the task to each machine that initiates the celery service to perform the task, and then to explore the source code and continue to share it.
Celery Getting Started