[英]Run Multiple Tasks Asynchronously in Python
所以這是我在端點之一中的最后兩行:
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)
返回self.response將返回我的其余客戶端201的響應。我的問題是send_activation_mail
似乎需要花一些時間才能運行,因此我的注冊端點需要花費很多時間。 我試圖找到一種在Python中同時異步執行這些任務的方法,以前有沒有人遇到過這種情況的經驗,如何解決呢?
您的意思是您要異步執行任務。 同步意味着在同一線程上按順序執行所有操作。
根據您的Python版本,您可以簽出多重處理模塊: https : //docs.python.org/2/library/multiprocessing.html 。
我通過使用線程threading.Thread(target=self.send_activation_mail(request=request, user=user)).start()
執行send_activation_mail之后解決了.thread threading.Thread(target=self.send_activation_mail(request=request, user=user)).start()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.