Running TurboGears behind Bjoern

Bjoern is a screamingly fast, ultra-lightweight asynchronous WSGI server that can be used to deploy your TurboGears application in a very simple and light-weight manner.

Note that the following documentation assumes you are using TurboGears 1.5.1 and CherryPy 3.2 or newer versions. We also assume that you are deploying on a Linux server, though this setup may be possible on other platforms as well.

Install bjoern

Before installing bjoern, check if the libev-devel package is installed on your system, otherwise install it via the package manager. Installing bjoern should then be as simple as:

pip install bjoern

Create a bjoern server script

We assume your TurboGears application is called myapp. Then to serve your application using bjoern, just run the following small Python script:

from bjoern import run
from myapp import command

application = command.start()
run(application, '', 80)

You can refine this script so that it can serve as a start script in /etc/init.d, or run this script indirectly via supervisor. For security reasons, the script should be run by a user with as little privileges as necessary to run your application.

Using a virtual environment

If you installed your TurboGears application in a virtual environment (as recommended), you should put the above server script into the bin subdirectory of your virtual environment, e.g. as Then simply add the following line to the import statements in this script:

import activate_this

If you have set up your virtual environment using --no-site-packages, and installed bjoern as a global package, then add this line below the line from bjoern import run, otherwise add it above that line.

Adapt your TurboGears Configuration

As you don’t need and want the CherryPy server to start when running the application via bjoern, add the following setting to the TurboGears configuration, preferably close to the environment setting:

engine.start = False