↓ Archives ↓

serving up python with the quickness

Inspired by Justin Lilly, I spent some time looking at various ways of running python web applications with an eye to performance. Nicholas Piël has done some great work testing and documenting many of them. Gevent looks like a great option as does CherryPy, but uWSGI caught my eye because it provides an nginx module and I'm already running lots of nginx. Since its fairly new, my stock nginx from the Ubuntu Karmic repository doesn't come with uWSGI, but compiling it in is trivial.

So I've added uwsgi and nginx + uwsgi to my launchpad ppa for anyone out there who'd like to give it a spin on Karmic. My initial impressions are very positive. If you want to try it out, you can add my ppa to your apt sources and simply run:

Starting up the wsgi server is easy. You can pass it a wsgi script to run, or you can pass it later dynamically using an environment variable 'UWSGI_SCRIPT'. Here's how I'm starting it right now:

This simply starts uwsgi as a background process and binds to TCP port 9001 on all interfaces. I'll probably write an upstart script to deal with this at some point, but this is working well at the moment. That's really all you need to do to run the uwsgi server. If that's all you wanted, then you're done, but you probably still need to setup a method to pass uwsgi requests to the uwsgi server. Here's how you do it with nginx:


  • [...] enough, my small effort in packaging uWSGI for Ubuntu was what prompted some communication with a RightScale employee who encouraged me to apply for a [...]

  • Aug 13th 201015:08
    by Robert Samurai


    Aside from the domain names, I have this exact same configuration. Except, my UWSGI_SCRIPT is set to "app.wsgi". But I get uwsgi error saying that no application was found when I try to visit site. My uwsgi.log says:

    ImportError: No module named app.wsgi

    However all the information i find is very ambiguous and doesn't layout what the UWSGI_SCRIPT value is or where it suppose to be saved. Is this suppose to be "app_wsgi.py" instead?

    • Aug 13th 201016:08
      by stevecrozz


      Hey Robert,

      It's my understanding that whatever you set UWSGI_SCRIPT to will be imported like a regular python module. In your case, uWSGI is looking in your application path for "app/wsgi.py" where "app" is a python module which simply means it has an __init__.py. If you can't get that to work you can try passing the script name directly to the binary which I've learned is faster anyway.

      If you're still having trouble you should join the mailing list and ask again (http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi).

  • Aug 16th 201016:08
    by Robert Samurai


    Thanks for pointing me in the right direction!

    The pylons project and the nested module use the same name. So that was throwing me off when setting the paths. Plus it appears I can't dynamically add pythonpaths to uwsgi from the environmental scripts in the nginx location block. Instead, I created an xml for uwsgi to load the paths from. Everything works fine now.

  • Jan 25th 201114:01
    by cobalt


    I get this:

    root@ubuntu:/etc/apt# sudo -u www-data uwsgi -s :9001 -d /var/log/uwsgi.log
    root@ubuntu:/etc/apt# open(): Permission denied [utils.c line 148]

    Any ideas?

    • Jan 25th 201117:01
      by stevecrozz


      Yes. You probably don't have permission to write to /var/log/uwsgi.log as www-data. Try creating a /var/log/uwsgi/ and chown it for www-data:www-data. Then point your logger to a new file in that path.

Leave a Reply