Django — Runserver development server is slow on cygwin

The django development server is extremely slow through cygwin and not very reliable in the long run due to a natural limitation of Cygwin running as a windows process: the vfork resource availability errors.

My solution is to set up multiple environments – one for cygwin and a separately compiled environment for windows. That way, I get the full speed of a native windows python and the full power of the unix shell.

Modify manage.py to detect platform

We need to modify sys.path on demand depending on which platform the command is run from.

#!/usr/bin/env python
import os
import sys
import platform

DIRNAME = os.path.dirname(__file__)

# detect platform - if windows, use winenv dir for windows specific builds
if platform.system().upper() == 'WINDOWS':
    env_path = '../winenv/Lib/site-packages' # path to your win env
else:
    env_path = '../env/lib/python2.6/site-packages' # path to your usual env

full_env_path = os.path.join(DIRNAME, env_path)
sys.path.insert(0, full_env_path)

print 'Environment path is... {path}'.format(path=full_env_path)

Set up your windows environment

Naturally you will need to have a python environment working in windows first.

I use a pip requirements file to deploy my libraries, so installing the separate environment is as easy as typing ‘pip install -E winenv -r pip_requirements.txt’ on my windows command prompt.

Enjoy high performance runserver

You’re done. Open up a windows command prompt and run the development server and forget about it! Develop on cygwin while windows runs the dev server.

1 Comment

Leave a Comment