问题描述
我在我的Web项目中有一个耗时的功能。当功能正在进行其计算时,应该呈现一个网页,通知用户计算结果后将通过电子邮件发送结果。如果我在函数调用后放置渲染,那么网页不会被渲染,直到time_consuming_function()完成,这将使响应无效。
views.py:
def web_function(request):
...
time_consuming_function()
return HttpResponse()
python线程是唯一的方法吗? / p>
更新
使用手机,因为它似乎比ztaskd更好的记录
我建议你看一个任务调度框架,如芹菜或者只是简单的)
I have in my web project a time consuming function. While the function is doing its computations, a web page should be rendered informing the user that the results will be sent by email once the computation is done.
If I put the rendering after the function call, the web page wont be rendered until after the time_consuming_function() had finished and that would make the response senseless.
views.py:
def web_function(request):
...
time_consuming_function()
return HttpResponse()
Is python threading the only way to go?
Update
Ended up using cellery, since it seemed better documented than ztaskd
I suggest you look at a task-scheduling framework, such as Celery (or just plain Rabbit MQ)
这篇关于在Django中同步多任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!