[yum-commits] Branch 'yum-3_2_X' - 2 commits - test/yum-leak-test.py yum/repos.py

James Antill james at osuosl.org
Thu Mar 19 15:38:14 UTC 2009


 test/yum-leak-test.py |   24 ++++++++++++++++++++++++
 yum/repos.py          |   20 +++++++++++++-------
 2 files changed, 37 insertions(+), 7 deletions(-)

New commits:
commit 34e4ca1e6d8c7f439767abf20cbfc3c59fb00c44
Author: James Antill <james at and.org>
Date:   Thu Mar 19 11:24:18 2009 -0400

    Update leak tester so we can more easily see the leaks

diff --git a/test/yum-leak-test.py b/test/yum-leak-test.py
index f3d6de3..bce4550 100755
--- a/test/yum-leak-test.py
+++ b/test/yum-leak-test.py
@@ -1,11 +1,35 @@
 #! /usr/bin/python -tt
 
 import yum, os, sys, time, gc
+from urlgrabber.progress import format_number
 
+def out_mem(pid):
+    ps = {}
+    for line in open("/proc/%d/status" % pid):
+        if line[-1] != '\n':
+            continue
+        data = line[:-1].split(':\t', 1)
+        if data[1].endswith(' kB'):
+            data[1] = data[1][:-3]
+        ps[data[0].strip().lower()] = data[1].strip()
+    if 'vmrss' in ps and 'vmsize' in ps:
+        print "* Memory : %5s RSS (%5sB VSZ)" % \
+                    (format_number(int(ps['vmrss']) * 1024),
+                     format_number(int(ps['vmsize']) * 1024))
+
+out_mem(os.getpid())
 while True:
     yb = yum.YumBase()
     yb.repos.setCacheDir(yum.misc.getCacheDir())
     yb.rpmdb.returnPackages()
     yb.pkgSack.returnPackages()
+    out_mem(os.getpid())
     time.sleep(4)
+
+    if False:
+       del yb
+       print len(gc.garbage)
+       if gc.garbage:
+           print gc.garbage[0]
+           print gc.get_referrers(gc.garbage[0])
     # print "DBG:", gc.get_referrers(yb)
commit 3fd8ca8835044f859fa9556b2425307289a3f9b4
Author: James Antill <james at and.org>
Date:   Thu Mar 19 11:05:35 2009 -0400

     Really fix the leak due to gpg_import_func.
     *hates python GC*

diff --git a/yum/repos.py b/yum/repos.py
index 63d1493..5185d98 100644
--- a/yum/repos.py
+++ b/yum/repos.py
@@ -25,6 +25,18 @@ from packageSack import MetaSack
 
 from weakref import proxy as weakref
 
+class _wrap_ayum_getKeyForRepo:
+    """ This is a wrapper for calling YumBase.getKeyForRepo() because
+        otherwise we take a real reference through the bound method and
+        that is d00m (this applies to YumBase and RepoStorage, hence why
+        we have a seperate class).
+        A "better" fix might be to explicitly pass the YumBase instance to
+        the callback ... API change! """
+    def __init__(self, ayum):
+        self.ayum = weakref(ayum)
+    def __call__(self, repo, callback=None):
+        return self.ayum.getKeyForRepo(repo, callback)
+
 class RepoStorage:
     """This class contains multiple repositories and core configuration data
        about them."""
@@ -44,15 +56,9 @@ class RepoStorage:
         # need to be set from outside of the repos object to do anything
         # even quasi-useful
         # defaults to what is probably sane-ish
-        self.gpg_import_func = self._wrap_ayum_getKeyForRepo
+        self.gpg_import_func = _wrap_ayum_getKeyForRepo(ayum)
         self.confirm_func = None
 
-    def _wrap_ayum_getKeyForRepo(repo, callback=None):
-        """ This is a wrapper for calling self.ayum.getKeyForRepo() because
-            otherwise we take a real reference through the bound method and
-            that is d00m. """
-        return self.ayum.getKeyForRepo(repo, callback)
-
     def doSetup(self, thisrepo = None):
         
         self.ayum.plugins.run('prereposetup')


More information about the Yum-commits mailing list