6

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!!

Joe Doherty
  • 3,778
  • 2
  • 31
  • 37
namit
  • 6,780
  • 4
  • 35
  • 41

2 Answers2

15

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)
A. Jesse Jiryu Davis
  • 23,641
  • 4
  • 57
  • 70
  • @Jesse: Now it is working.. i also tried to make `processes=10` on windows; it stopped at `os.fork()`; ok then i have to move my app to better alternate; like linux machine; in this way i have to specify number of processes??; so is there any way that my app automatically add new process on each new request?? – namit Mar 11 '14 at 14:12
  • 1
    Consult the docs for `run_simple`, here: http://werkzeug.pocoo.org/docs/serving/#werkzeug.serving.run_simple All arguments to `app.run` are passed to `run_simple`. On Windows, use multithreading. On Linux, use multiple threads and / or processes. – A. Jesse Jiryu Davis Mar 11 '14 at 16:18
1

If you're using WSGI's run_simple function just add the threaded=true param.

Example:

run_simple('0.0.0.0', 9370, application, use_reloader=True, use_debugger=True, threaded=True)
Nick Woodhams
  • 11,977
  • 10
  • 50
  • 52