Django Simple example to add 2 numbers


To get started:

  1. Install celery pip install celery
  2. configure celery (head to the remarks section)
from __future__ import absolute_import, unicode_literals

from celery.decorators import 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.


async_result_object = add_number.delay(5, 10)
if async_result_object.ready():