The real-time web with co-routines

Audience level:
Web Frameworks
March 7th 1:20 p.m. – 4:40 p.m.


Learn how to build fast and interactive web applications using a wsgi compliant web framework and co-routines. Utilizing Redis/ZeroMQ, Socket.IO, and GEvent you will learn how to build a responsive and concurrent web app while maintaining good test coverage.


We will build a collaborative todo list system that will show you how to utilize Python, Redis/ZeroMQ,, and GEvent for real-time communication.

We will focus on the following topics:

  • Using a wsgi framework to build a RESTful interface and hooking up to it.
  • Using socketio and redis/zeromq for subscribing to named channels and communicating in real-time over websockets.
  • Gevent
  • Testing your real-time application
  • Deployment and Monitoring

A rough outline

GEvent (30 min)

Intro to GEvent and co-routines, what it is, how it works, the benefits of using it, and how simple it is to wrap your mind around a co-routine vs the callback methodology of threads.

ZeroMQ / Redis (30 min)

Intro to pub/sub, the communication model we'll use for our realtime communication and how to utilize ZeroMQ or Redis to achieve this.

Socket.IO and Backbone.js (30 min)

Discussion of Polling, Longpolling, Flash sockets, and web sockets and the benefits of each and how Socket.IO lets us not care. I will discuss how to get client side working with the server side.

Testing (15 min)

We will cover how to architect your co-routine based applications to make them easily testable and how to utilize mock to make things easier. We will cover the gotcha's of testing GEvent based code.

Deployment (15 min)

The final portion of the tutorial we discuss deployment and how to manage and monitor your WSGI server that is using GEvent patched libraries. This will cover basics on which webservers to use as well as exception handling.

We leave 30minutes of leeway to further discussion in a certain area that the students are most interested in as well as for questions on things specific that they feel I may not have covered so far.

I will provide the non-realtime code base for the application we will be working on and we will start from there and slowly add in support for the realtime communication as we discuss the technologies needed.

Most introductions to the web with gevent just show a basic chat application which leaves a lot of questions about where to go next once you are building a real application and I hope to cover all of those in this tutorial.