| « Specifically designed to be readable | Vellum coming along nicely » |
Marius Gedminas just wrote a post on memory leaks. He could have used Dowser to find the leak more easily, I'll bet.
Dowser is a CherryPy application for monitoring and managing object references in your Python program. Because CherryPy runs everything (even the listening HTTP socket) in its own threads, it's a snap to include Dowser in any Python process. Dowser is also very lightweight (because CherryPy is). Here's how I added it to a Twisted project we're using at work:
...
from twisted.application import service
application = service.Application("My Server")
s.setServiceParent(application)
import cherrypy
from misc import dowser
cherrypy.config.update({'server.socket_port': 8088})
cherrypy.tree.mount(dowser.Root())
cherrypy.engine.autoreload.unsubscribe()
# Windows only
cherrypy._console_control_handler.unsubscribe()
cherrypy.engine.start()
from twisted.internet import reactor
reactor.addSystemEventTrigger('after', 'shutdown', cherrypy.engine.exit)
The lines before 'import cherrypy' already existed and are here just for context (this is a Twisted service.tac module). Let's quickly discuss the new code:
Then browse to http://localhost:8088/ and you'll see pretty sparklines of all the objects. Change the URL to http://localhost:8088/?floor=20 to see graphs for only those objects which have 20 or more objects.

Then, just click on the 'TRACE' links to get lots more information about each object. See the Dowser wiki page for more details and screenshots.
Have you got a recipe for dowser with Turbogears? I have a nasty memory leak I'd love to squash.
Thanks, this is an interesting app that I hadn't known about.
Rob,
The dowser package consists of a single CherryPy Root object. You should be able to mount it on your Turbogears app like any other controller:
cherrypy.tree.mount(dowser.Root(), '/dowser', config)
I'm using the stable version of Turbogears which is based on CherryPy 2, but dowser seems to only work with CherryPy 3.
from cherrypy import tools
ImportError: cannot import name tools
I got around that, but then there's quickstart. Do you think it'll be port-able to CP 2 without too much work?
Thanks,
Rob
Rob, CP 2.3 support added in http://www.aminus.net/changeset/137. You may have to tweak the staticfilter and/or url settings if you mount dowser somewhere other than /.
Awesome, thanks, I'll give it a shot with TurboGears.
What license is this under? I don't see any license in the code or svn tree.
For Turbogears it was as simple as:
import dowser
Then in my Root controller:
class Root(controllers.RootController):
memleak = dowser.Root()
Then point your browser at
localhost:7878/memleak
Hmmm. Now to figure out what all that output is telling me...
Here's a minimal but complete example for anyone just trying to get started.
import cherrypy
import dowser
class Root:
@cherrypy.expose
def index(self):
return "hello, world."
index.exposed = True
if name == 'main':
cherrypy.engine.autoreload.unsubscribe()
cherrypy.config.update({'server.socket_port': 8088})
# http://localhost:8088/dowser
cherrypy.tree.mount(dowser.Root(), '/dowser')
# http://localhost:8088/
# hello, world.
cherrypy.quickstart(Root(),'/')