Re: [flask] Multithreaded Passenger
- From:
- Simon Sapin
- Date:
- 2011-04-04 @ 04:17
Le 04/04/2011 02:49, Joe Esposito a écrit :
> So is it enough to do the following to enable multithreaded request
> handling for a Passenger Flask app when using Dreamhost?
>
> app = Flask(__name__)
> app.threaded = True
>
> I seem to be getting mixed results though. Sometimes, long processing
> can take place while handling another fast request and other times it
> waits until the processing is done.
> Restated: Is there an easy way to have Passenger work in production
> the same way that "app.run(threaded=True)" does on my local machine?
>
Hi,
You should not confuse you application, the "app" object, which is juts
a callable object that follows the WSGI protocol, and WSGI servers.
Apache+mod_wsgi, Apache+Passenger or nginx+flup (among others) are
popular solutions for such a server in production. Flask itself comes
with a development server written in Python that you can invoke with
app.run(). However this server is *not* part of you application.
Flask’s server is meant to be used during development. In its default
configuration, it runs everything in a single thread and thus can only
process one request at the same time. You can however call it with
app.run(threaded=True) and it will run each request in a separate
thread, allowing them to run concurrently. I don’t think app.threaded
does anything. You should not use app.run(...) with another server.
Anything I just said about Flask’s development server in not relevant to
any other server. They all have their own concurrency model. I’d be
surprised if Passenger did not have some form of concurrency, but it
also depends on it’s configuration. That is, configuration of the
server, not the application.
I don’t know the specifics for Dreamhost, but chances are you’re not in
control of the server configuration (which is shared.) That’s what you
get with shared hosting.
Regards,
--
Simon Sapin
http://exyr.org/