Python Django异步请求处理 [英] Python Django Asynchronous Request handling

查看:802
本文介绍了Python Django异步请求处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个应用程序中工作,我正在做一个巨大的数据处理,以生成一组全新的数据,然后最终保存到数据库。该应用程序正在花费巨大的时间处理和保存数据到数据库。我想在一定程度上改进用户体验,首先将用户重定向到结果页面,然后在后台执行数据保存部分(可能是异步方式)。我的问题是,为了显示结果页面,我需要拥有一组新的处理数据。有没有办法,我可以这样做,数据处理和数据保存部分是在后台完成的,每当数据处理部分完成(在保存到数据库之前),我会得到结果页面中的处理数据。

解决方案

异步任务可以在Python中使用芹菜。您可以简单地将任务推送到Celery队列,任务将以异步方式执行。然后,您可以从结果页面进行一些轮询,以检查是否完成。



其他替代方法可以是像龙卷风


I am working in an application where i am doing a huge data processing to generate a completely new set of data which is then finally saved to database. The application is taking a huge time in processing and saving the data to data base. I want to improve the user experience to some extent by redirecting user to result page first and then doing the data saving part in background(may be in the asynchronous way) . My problem is that for displaying the result page i need to have the new set of processed data. Is there any way that i can do so that the data processing and data saving part is done in background and whenever the data processing part is completed(before saving to database) i would get the processed data in result page?.

解决方案

Asynchronous tasks can be accomplished in Python using Celery. You can simply push the task to Celery queue and the task will be performed in an asynchronous way. You can then do some polling from the result page to check if it is completed.

Other alternative can be something like Tornado.

这篇关于Python Django异步请求处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆