Flask应用程序在处理请求时挂起 [英] Flask app hangs while processing the request
问题描述
在最后,我导出结果数据框,使其与大熊猫(如果存在以前存储的Excel的更新)优秀。
和GET请求我返回这个数据帧的结果。
现在的问题是...应用程序没有回应,而那些5-10秒。即使我从另一台电脑访问我的应用程序,这将在5-10秒完成后显示。
这意味着如果这个应用程序的任何用户已经上传他的文件;然后休息别人不得不等待,直到他的工作完成。
我甚至在我的应用程序中添加了下面提到的代码;但是没有任何改进。
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ .ioloop import IOLoop
$ b $ if if __name__ =='__main__':
http_server = HTTPServer(WSGIContainer(app))
http_server.listen(5657)
IOLoop.instance ().start()
也是我的系统和python版本如下..。
>>> sys.version
'2.7.5 | Anaconda 1.8.0(32-bit)| (默认,2013年7月1日,12:41:55)[MSC v.1500 32位(Intel)]'
$ b $注意:我想把它移动到python3.3,并希望保留在我的Windows 7的机器上!
< Tornado通常是一个单线程的Web服务器。如果您专门为Tornado的异步风格编写代码,则可以同时处理多个请求,但在您的情况下,您并未这么做;您只需要使用Tornado来为Flask提供请求。
删除Tornado并尝试使用Flask的多线程选项:
app.run(threaded = True)
I have a simple flask app, single page, upload html and then do some processing on it on the POST; at POST request; i am using beautifulsoup, pandas and usually it takes 5-10 sec to complete the task.
at the end i export the resultant dataframe to excel with pandas(with the update of the previous stored excel if present).
and on GET request i return the result of this dataframe.
Now issue is... app gives no response while those 5-10 sec.; even if i visit my app from another computer; it will show after the completion of those 5-10 sec.
It means if any user of this app has uploaded his file; then rest others have to wait till his job completes.
i have even added the below mentioned code in my app; but no improvement.
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
if __name__ == '__main__':
http_server = HTTPServer(WSGIContainer(app))
http_server.listen(5657)
IOLoop.instance().start()
also my system and python version is as below.. .
>>> sys.version
'2.7.5 |Anaconda 1.8.0 (32-bit)| (default, Jul 1 2013, 12:41:55) [MSC v.1500 32 bit (Intel)]'
Note: i want to move it to python3.3, and wanted to remain on my windows 7 machine!!
Tornado is, typically, a single-threaded web server. If you write code specially for Tornado's asynchronous style you can process multiple requests concurrently, but in your case you aren't doing that; you're just using Tornado to serve requests with Flask, one at a time.
Remove Tornado and try using Flask's multithreaded option:
app.run(threaded=True)
这篇关于Flask应用程序在处理请求时挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!