hello pocoo devs, trying to have event based responses in a flask webserver (server sent events, maybe later websockets), and given asyncio is starting to be the way to go for everything event-based, i tried to use those two technologies together by means of the aiohttp web server (which is wsgi compatible with the addition that wsgi applications can be coroutines and `yield from` things they want to wait for).
i've assembled a minimal working example on [1] (see there for source, links, and further comments); it demos a server that serves flask applications and also routes an eventsource resource, which sends an update to the browser every two seconds. the main hack i had to use was subclass my wsgi app from app.response_class, so it wouldn't get mangled through make_response, force_type and run_wsgi_app, which would terribly screw with it. (which is not surprising; they can't know that they should only continue iterating through the coroutine when the last yielded future has been done). so all in all, the hack works, but is neither pretty, nor does it preserve all of flask's qualities (eg the debugger is lost). i tried fixing that, but flask/werkzeug is too new and/or complex for me to do that easily. * do you think werkzeug could grow to understand wsgi coroutine apps easily? * how severe breakage do you think has to be expected when bypassing the run_wsgi_app mechanisms (in terms of simultaneous database access, sidestepping locks etc)? best regards chrysn [1] https://www.gitorious.org/aiohttp-werkzeug-demo/aiohttp-werkzeug-demo/ -- To use raw power is to make yourself infinitely vulnerable to greater powers. -- Bene Gesserit axiom
signature.asc
Description: Digital signature
