Commits

Robert Brewer  committed c259b1c

Adding optional objgraph import to gctools.

  • Participants
  • Parent commits d492efa

Comments (0)

Files changed (1)

File cherrypy/lib/gctools.py

 import gc
 import inspect
+import os
+import sys
+ 
+try:
+    import objgraph
+except ImportError:
+    objgraph = None
 
+import cherrypy
 from cherrypy import _cprequest
 
 
                         "\nExpected %s to %s %r references, got %s." %
                         (minobj, maxobj, cls, lenobj))
                 for obj in objs:
+                    if objgraph is not None:
+                        gfile = os.path.join(
+                            os.getcwd(), "graph_%s.png" % id(obj))
+                        objgraph.show_refs(
+                            obj, extra_ignore=[id(objs), id(sys._getframe())],
+                            max_depth=4, too_many=20,
+                            filename=gfile)
                     output.append("\nReferrers for %s:" % repr(obj))
                     t = ReferrerTree(ignore=[objs], maxdepth=3)
                     tree = t.ascend(obj)