Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Async Task Channels Demo

The demo goes with the talk Async Tasks with Django Channels given at PyCon Canada 2016

It is split up into a few different step with tags so you can more easily see how it was built up.


git clone
cd asyncdemo
git checkout step1

At this point, the code is for a basic Django 1.10 web app. Get into your favorite type of virtual env and then run the following.

pip install -r requirements.text
cd asyncdemo
python migrate
python runserver

Now you should have the hello_view being served at You can append "?name=yourname" to change the name displayed.

Meanwhile, there is a simulated slow network call which writes out the hello message to the console and takes between 5 and 30 seconds to do it.


git checkout step2
python runserver

This has updated requirements.txt and and created a which is even to get Django to run with Channels. The view remains unchanged, so it will still be slow when you runserver. You can see though the output Django produces when you runserver has been changed.

step 3

git checkout step3
python runserver

A "notify" channel has been declared and the view now uses it. When you runserver the website is more responsive, but if you hammer it those slow 30 second simulated network calls will gum up the system.


git checkout bonusround

This changes channels to use redis as the broker of messages. Even to runserver you will need to have redis running locally.

When you do you will get the same behavior of step 3. To get around the slow down under load we will need to run everything in separate processes, in separate terminals.

daphne asyncdemo.asgi:channel_layer --port 8000

This runs the interface server in it's own process. If you try to connect now it will time out because there are no workers running.

You can run workers in as many separate terminals as you like:

python runworker

But the key to trying to maintain throughput is to run a worker which will never be tied up with a notification task:

python runworker --exclude-channels=notify

This worker will ensure that hello_view remains responsive.


Demo code for Async Task with Django Channels at PyCon Canada 2016



No packages published
You can’t perform that action at this time.