Flask application freezes when processing request

I have a simple flash application, one page, loading html and subsequent processing on it in POST; on request POST; I use beautifulsoup, pandas and it usually takes 5-10 seconds to complete the task.

in the end, I export the resulting data frame to succeed with pandas (with updating the previous saved excel, if present). and at the request of GET, I return the result of this frame.

Now the question is: the application does not give an answer while those 5-10 sec .; even if I visit the application from another computer; it will be shown after completing these 5-10 sec. This means that any user of this application has uploaded their file; then the rest should wait until his work is completed.

I even added the code below in my application; 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 are given 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 port it to python3.3 and wanted to stay on my windows 7 machine.

+6
source share
2 answers

Tornado is usually a single-threaded web server. If you write code specifically for the asynchronous Tornado style, you can handle several requests at the same time, but in your case you do not; you just use Tornado to serve requests with Flask, one at a time.

Uninstall Tornado and try using the multi-threaded Flask option:

 app.run(threaded=True) 
+13
source

If you are using the WSGI run_simple function, just add the parameter threaded=true .

Example:

 run_simple('0.0.0.0', 9370, application, use_reloader=True, use_debugger=True, threaded=True) 
0
source

All Articles