librelist archives

« back to archive

Flask ported to asyncio

Flask ported to asyncio

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

https://github.com/mrdon/flask

It looks like this [1]:

----

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

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

@app.route("/hello/<string:name>")
@coroutine
def say_hi(name):
    yield from sleep(2)
    return "it worked %s" % request.args.get("name", name)

app.run()

-----

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.

Don

[1] https://github.com/mrdon/flask/blob/master/hello.py