0

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?

Putra
  • 399
  • 9
  • 23

2 Answers2

1

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.

sbrannon
  • 180
  • 1
  • 6
  • Sorry I edited my question. Is that mean if I run 2 different task in different thread and one of the task is a return task, is the other task being canceled after the return task executed? – Putra Mar 01 '18 at 05:16
0

It solved after I execute send_activation_mail by using threading threading.Thread(target=self.send_activation_mail(request=request, user=user)).start()

Putra
  • 399
  • 9
  • 23