Side Channel

  • home
  • resources
Home › Blogs › kamal's blog

User login

What is OpenID?
  • Log in using OpenID
  • Cancel OpenID login
  • Create new account
  • Request new password

Navigation

  • Books
  • Feed aggregator

Recent blog posts

  • Ubuntu mirrors up and improved!
  • Google-jstemplate: Iterate object with unknown properties
  • nginx https proxypass for php apps
  • sugarcrm & memcache: Doing it Wrong
  • subversion and https in Ubuntu Karmic
  • Drupal: Views block delta converted to md5 hash
  • Ubuntu Server install requires PAE
  • Installing Drupal from command line
  • Drupal: Handling form field weight through CCK
  • minify javascript using Google Closure Compiler
more

angch's location

angch twitter

  • angch: Heading to Brunei. Business class for a change.
more

Debugging WSGI Application

kamal's picture

kamal — Thu, 05/11/2009 - 09:09

One thing everyone like in PHP, print statement just work. You don't need any fancy debugger.

DebuggingTechniques does explain it well on how to debug your WSGI apps. It also explain why print would not work, all for good reason. My favorite debugger is the web debugger from Werkzeug but as explained in the wiki, to make it work with mod_wsgi you must make sure subsequent request from the debugger end up in the same process that trigger the error. That mean:-

StartServers 1
ServerLimit 1

In your apache config. Problem with this one is that you'll quickly noticed a problem when loading page that make multiple parallel requests (background ajax for example). I try to experiment with using nginx to proxy the request to the dev server (simulating deployment scenario) but so far doesn't work really well when using some 'fancy' server arrangement. For example in my case, nginx is handling the main request, proxied it to the second server running apache but the application is mounted not under the root path (both under nginx and apache).

server {
  server_name someserver.com;

  location /app/django {
    proxy_pass http://server2.com/;
  }
}

  <VirtualHost *>
    servername someserver.com

    WSGIAliasScript /app/django /path/to/somescript.wsgi
  </VirtualHost>

Note, the above config not meant to be correct, I just want to 'visualize' the arrangement. If proxied to the dev server, it would appear to the app that it is mounted under the root path which is not the case under deployment. In those setup, /app/django is considered as SCRIPT_NAME and everything else is PATH_INFO which Django use to construct request path. With a dev server, the whole /app/django/some/path would be used as PATH_INFO.

The debugger seem to work under daemon mode with one process and 1 thread as stated in the wiki page. So far I've been using mod_wsgi through embedded mode but it seem that the daemon mode also work fine. The bonus with daemon mode is also I don't have to restart apache much often anymore, just touch the wsgi script file and the whole application would be reloaded.

  • debugging
  • python
  • wsgi
  • kamal's blog
  • Add new comment


Creative Commons License

  • home
  • resources

Standard Disclaimer.