To get started:
pip install celery
from __future__ import absolute_import, unicode_literals
from celery.decorators import task
@task
def add_number(x, y):
return x + y
You can run this asynchronously by using the .delay()
method.
add_number.delay(5, 10)
, where 5 and 10 are the arguments for the function add_number
To check if the async function has finished the operation, you can use the .ready()
function on the async object returned by the delay
method.
To fetch the result of the computation, you can use the .result
attribute on the async object.
Example
async_result_object = add_number.delay(5, 10)
if async_result_object.ready():
print(async_result_object.result)