Reputation: 431
So this is my last 2 lines in one of my endpoint:
self.send_activation_mail(request, user=user)
return self.response(request, status=201, title='Created', description='Please check your email for activation', data=user_data)
returning self.response will be return the my rest client a response of 201. My problem is the send_activation_mail
seems like takes time to run so the my endpoint to signup process takes so much time. I tried to find the way to execute those tasks at the same time asynchronously in Python.Does anyone has any experience with this kind of situation before and how do you solve it?
Upvotes: 0
Views: 1239
Reputation: 431
It solved after I execute send_activation_mail by using threading threading.Thread(target=self.send_activation_mail(request=request, user=user)).start()
Upvotes: 0
Reputation: 180
You mean that you want to execute the tasks asynchronously. Synchronously means executing everything in order, on the same thread.
Depending on your version of Python, you can check out the multiprocessing module: https://docs.python.org/2/library/multiprocessing.html.
Upvotes: 1