Is Django post_save signal asynchronous?
Also look into celery (or more specifically django-celery). It is an async task scheduler / handler. So your post_save signal handler creates a task, which is picked up and executed through celery. That way you still have your speedy application, while the heavy lifting is performed async, even on a different machine or batch of machines.
What you want is a thread. They're very easy to use. You just subclass threading.Thread
and write a run
method:
import threading
class LikeThread(threading.Thread):
def __init__(self, user, liked, **kwargs):
self.user = user
self.liked = liked
super(LikeThread, self).__init__(**kwargs)
def run(self):
# long running code here
Then, when your ready to do the task, you fire it off with:
LikeThread(request.user, something).start()
The rest of your view code or whatever will resume and return the response, and the thread will happily do its work until it's done and then end itself.
See full documentation: http://docs.python.org/library/threading.html