[Django]-Django, Python calling Python code without waiting for response?

6đź‘Ť

âś…

Can’t vouch for it because I haven’t used it yet, but “Celery” does pretty much what you’re asking for and was originally built specifically for Django.

http://celeryproject.org/

Their example showing a simple task adding two numbers:

from celery.decorators import task

@task
def add(x, y):
    return x + y

You can execute the task in the background, or wait for it to finish:

>>> result = add.delay(8, 8)
>>> result.wait() # wait for and return the result
16

You’ll probably need to install RabbitMQ also to get it working, so it might be more complicated of a solution than you’re looking for, but it will achieve your goals.

👤dkamins

0đź‘Ť

You want an asynchronous message manager. I’ve got a tutorial on integrating Gearman with Django. Any pickleable Python object can be sent to Gearman, which will do all the work and post the results wherever you want; the tutorial includes examples of posting back to the Django database (it also shows how to use the ORM outside of Django).

👤Elf Sternberg

Leave a comment