hello don,

On Mon, Feb 17, 2014 at 04:42:52PM -0700, Don Brown wrote:
> I'm wondering how possible this really is.  Flask and Bottle, at least,
> depend on setting a thread-local variable to store the current request,
> response, and general environment, but with asyncio allowing multiple
> concurrent requests on a single process/thread, those variables start
> getting stepped.  In particular, my Flask fork is having issues as Flask
> keeps complaining the request is incorrect ("Popped wrong request
> context."), but given the nature of concurrent requests, it isn't 100%
> consistent.
> 
> Therefore, I wonder if the current popular web frameworks can be used at
> all, and instead, we'd have to rewrite one or more to not depend on
> thread-local variables, among other things.

flask (and other werkzeug-based frameworks) seem not to use thread-local
variables directly, but have their own "local" manager[1]. especially,
the flask RequestContext objects (which fling the described exceptions)
use that mechanism.

using your hello.py example, i'll try whether it is sufficient to adapt
the local module to not be thread-local, but "request-local". (not sure
where to hook it up exactly, might need dirty stuff like stack
inspection for a first hack).

i'm very new to flask (used django and pylons ages ago, and just
recently needed web stuff again), but it is too nice not to try to use
it with asyncio :-)

best regards
chrysn

[1] http://werkzeug.pocoo.org/docs/local/

-- 
To use raw power is to make yourself infinitely vulnerable to greater powers.
  -- Bene Gesserit axiom

Attachment: signature.asc
Description: Digital signature

Reply via email to