Skip to content

Instantly share code, notes, and snippets.

@EkkoG
Last active January 1, 2018 07:49
Show Gist options
  • Save EkkoG/ca77e82389437678a9bb87a501116304 to your computer and use it in GitHub Desktop.
Save EkkoG/ca77e82389437678a9bb87a501116304 to your computer and use it in GitHub Desktop.

Run Flask app with aiohttp and uvloop

hello_world.py

"""Simple demo of using Flask with aiohttp via aiohttp-wsgi's
WSGIHandler.

"""

import asyncio
from aiohttp import web
from aiohttp_wsgi import WSGIHandler
from flask import Flask

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

aio_app = web.Application()
wsgi = WSGIHandler(app)
aio_app.router.add_route('*', '/{path_info: *}', wsgi.handle_request)

@app.route('/')
def index():
    return 'hello world!'
pip3 install uvloop aiohttp flask aiohttp-wsgi gunicorn
gunicorn -k aiohttp.worker.GunicornUVLoopWebWorker -b 127.0.0.1:5000 hello_world:aio_app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment