librelist archives

« back to archive

Flask ported to asyncio

Flask ported to asyncio

Don Brown
2014-01-20 @ 23:47
I wanted to use my favorite python web framework with the new asyncio, so I
ported Flask:

It looks like this [1]:


from asyncio import coroutine, sleep
from flask import Flask, request

app = Flask(__name__)
app.config['DEBUG'] = True

def say_hi(name):
    yield from sleep(2)
    return "it worked %s" % request.args.get("name", name)


Given that it liters asyncio calls and "yield from" all over the place, I
don't imagine it should go in master, but if anyone wants to try out
asyncio but start somewhere familiar, it may be useful.