Chris Miles (chrismiles) wrote,
Chris Miles
chrismiles

Examining & killing request threads in Pylons

I've been working with Pylons quite a lot lately and have been very impressed. Today I discovered a handy tool for debugging Pylons (and any WSGI/Paster served apps) that provides a web interface to enumerate, poke at, and even kill currently active request threads.

It is called "egg:Paste#watch_threads" (if you can call that a name) and obviously it is a feature of Paster (so if you serve your Pylons app via mod_wsgi, for example, you wouldn't be able to use it; not that it is recommended to enable it in a production environment given the information/power it exposes).

Enabling it for a Pylons app is simply a matter of modifying the config file (development.ini). It took me a bit of scanning of the Paster docs to work out how to get the config correct, so I'll share the simple magic here.

You need to replace this part of the Pylons config (e.g. development.ini):
[app:main]
use = egg:Myapp
full_stack = true

with this:
[composite:main]
use = egg:Paste#urlmap
/ = myapp
/.tracker = watch_threads

[app:watch_threads]
use = egg:Paste#watch_threads
allow_kill = true

[app:myapp]
use = egg:Myapp
full_stack = true
#... rest of app config ...


What we are doing is replacing the main app with a composite app. The composite app uses "egg:Paste#urlmap" to mount the Pylons app at "/" while also mounting the "watch_threads" app at "/.tracker" (use whatever path you like; I borrowed from the examples I found).

So now if you fire up the Pylons application it should behave like normal, but you should also be able to browse to "/.tracker" (e.g. http://127.0.0.1:5000/.tracker) to see the active request thread debugger.

Below is a screenshot demonstrating watch_threads examining a Pylons app I was working on. Two threads are active; the request/WSGI environment is being shown for one of them.

Tags: debugging, paster, pylons, python, threads, wsgi
Subscribe

  • 3 comments
  • 3 comments

Comments for this post were locked by the author