I’ve been playing with Flask and WSGI in general for a few nights… at some point I started playing with pyuv and http-parser and before I realized I had a really basic WSGI server to play with: uvwsgi.
It’s not meant for production usage (yet) but should be really simple to understand, it’s less than 400 lines of code!
Here is a list of things I’d like to implement, in no particular order:
Multi-process support using socket sharing
Multi-process support using a single acceptor and a pool of worked which get connections dispatched round-robin
Update http-parser to the latest and greatest version
A few days ago I started playing a bit with Flask, since I’m considering it as the framework to build some API server. I have no web development experience, and Flask looks like a great project so I went with that.
I started with a tiny little hello world, and then I wanted to add some websockets and some CSS. Oh the trouble. When I started looking for how to combine a Flask app with WebSockets I found references to gevent-socketio for the most part, but I somewhat wanted to use Twisted this time, so I kept looking. Soon enough I found AutoBahn, a great WebSocket implementation for Twisted, which can be combined with a WSGI app, brilliant! After seeing how AutoBahn manages to add the websocket route to the WSGI app, adding support for static files was kind of trivial.
Here is the result of my experiments, a really simple web app which consists of a Flask WSGI app, a WebSocket server and some static files, all served by the same process running Twisted. You may not want to do this in a production environment, but hey, I’m just playing here 🙂
Since Gist does not currently allow folders, make sure you keep this layout after downloading the files:
We’ll use the twistd command line tool to launch out application, since it can take care of logging, running as a daemon, etc. To run it in the foreground:
twistd -n -l - -y app.py
This will launch the application in non-daemon mode and log to standard output.
Hope this helps someone, all feedback is more than welcome 🙂