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?

1

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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?
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.