Issue
I have the following:
def save(self):
for lang in ["es", "ar"]:
setattr(self, "title_" + lang, translateField(self.title, lang))
super(Landmarks, self).save()
The translateField
function calls Microsoft translator API, which takes some time to finish executing.
Is it possible to do the same asynchronously?
Solution
Django is not an asynchronous framework.
You need an asynchronous job/task queue, like celery:
Celery is an asynchronous task queue/job queue based on distributed message passing. It is focused on real-time operation, but supports scheduling as well.
django-celery package makes it easier to integrate django and celery.
There is also a Redis Queue project:
RQ (Redis Queue) is a simple Python library for queueing jobs and processing them in the background with workers. It is backed by Redis and it is designed to have a low barrier to entry. It should be integrated in your web stack easily.
Also see:
Answered By - alecxe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.