The Python Oracle

Django, Python calling Python code without waiting for response?

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Realization

--

Chapters
00:00 Question
01:19 Accepted answer (Score 6)
02:05 Answer 2 (Score 0)
02:35 Thank you

--

Full question
https://stackoverflow.com/questions/3806...

Accepted answer links:
http://celeryproject.org/
[RabbitMQ]: http://celeryq.org/docs/getting-started/...

Answer 2 links:
[a tutorial]: http://www.elfsternberg.com/2010/08/18/d.../

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #django #longrunningprocesses

#avk47



ACCEPTED ANSWER

Score 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.




ANSWER 2

Score 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).