Tracking memory leaks with dowser

1 minute read

Dowser in tornado

Dowser is a CherryPy application that displays sparklines of Python object counts, and allows you to trace their referents. This helps you track memory usage and leaks in any Python program, but especially CherryPy sites.

And CherryPy is WSGI enabled.

Tornado 默认的 http server 是非 wsgi 协议的,所以需要用其 WSGIContainer 进行转换

import dowser
import cherrypy
from tornado.wsgi import WSGIContainer

dowser_app = WSGIContainer(cherrypy.tree.mount(dowser.Root(), '/_dowser'))
handlers.insert(0, (r'/_dowser.*', tornado.web.FallbackHandler, dict(fallback=dowser_app)))

后两句用于将一个 wsgi 的应用运行于 tornado http server

自此即可在 http://domain:port/_dowser 进行查看各个对象引用数及增长状况等信息

Dowser in django

有现成的 app 可用: