hello pocoo-devs, On Thu, Feb 20, 2014 at 07:30:25PM +0100, Markus Unterwaditzer wrote: > >do you think the approach of [2] is feasible for future asyncio backend > >support in werkzeug? > > > > Which exact changes do you mean? I looked a bit in that repository > and at least the code in werkzeug.local doesn't seem to have > changed. The recent commits by mrdon are also unrelated.
apart from careless unrelated changes (probably remnants from testing),
the changes to flask are exclusively turning expressions into `yield
from`-expressions (sometimes wrapping them in call_maybe_yield); this
turns the functions into generators, so they can be used as asyncio
tasks[1].
the changes to werkzeug[2] are only slightly more complex, but are still
mostly `yield from`-instead-of-call, and some loop handling when it
comes to running a standalone server (also in the unit tests).
if it helps, i can try to fashion that into something that is more of a
single minimal patch -- but i don't think we are at the point where this
is a matter of having a patch to apply.
the more important question is: how can we have a werkzeug that supports
both classical (blocking threads vs asyncio) operation.
application-side, that's not an issue: mrdon's branch can run both
classical flask apps and coroutines. i see three big open questions:
* does pocoo want to support async operation? (i'm willing to spend time
on this, but not if i'm the only one to use it).
i've seen that twisted+werkzeug is supported by an external module
again (yay for yet another route function); was it tried to have
mainline werkzeug supported on twisted? (given the similarities
between twisted and asyncio, i reckon challenges would be similar).
* which idiom will be used for asynchronous flask apps?
i think that mrdon's
@app.route('/ping/<address>')
@asyncio.coroutine
def ping(address):
latency = yield from icmp.ping(address)
return render_template('pingresult.html', address=address,
latency=latency)
is good, but i don't have a good solution at hand yet for sending
partial data (as in pep-3333's `start_response(...); sleep(1); yield
first_chunk`) -- currently, i return a wsgi object for these purposes.
* how can a single code base serve both classical and asyncio operation?
this affects python < 3.3, where there is no `yield from` yet, but is
also tricky in newer versions, because having a `yield` in a function
makes it a generator no matter whether it's conditional or not.
as this is an issue with all libraries starting to support asyncio,
chances are that methods for this will be collected at the
python-tulip mailing list.
best regards
chrysn
[1] git diff --color-words 97411..f77e43cd4 flask
[2] git diff 65680068..1e42251e28 werkzeug
--
To use raw power is to make yourself infinitely vulnerable to greater powers.
-- Bene Gesserit axiom
signature.asc
Description: Digital signature
