Django请求/响应多线程处理

2024-05-16 08:31:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我的应用程序的工作流是-

User submits a file
On receiving -> process_file()
return response

如果process_file()花费大量时间,这可能会导致超时,那么我如何才能在之前将response发回,然后再处理该文件并将所需的输出发送给用户。
我已经检查了django芹菜,但我认为它是相当沉重的一个小应用程序,我正试图建立。在

更新:我在网上搜索了一下,如果有人想用芹菜,这里有一篇不错的博文,可以帮助你解决这个问题-[Link]


Tags: 文件用户应用程序returnonresponse时间process
1条回答
网友
1楼 · 发布于 2024-05-16 08:31:46

您可以使用Celery来处理这个问题:

Celery is an asynchronous task queue/job queue based on distributed message passing. It is focused on real-time operation, but supports scheduling as well.

The execution units, called tasks, are executed concurrently on a single or more worker servers using multiprocessing, Eventlet, or gevent. Tasks can execute asynchronously (in the background) or synchronously (wait until ready).

相关问题 更多 >