This patch changes to apply the wrapper on class method instead of
instance method to avoid the circular refrence caused by wrapping
instance method. Without this fix, it's observed the libvirt object
like 'virDomain' are leaked and the memory usage of kimchi grow rapidly.
Signed-off-by: Mark Wu <
wu...@linux.vnet.ibm.com>
---
src/kimchi/model.py | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/src/kimchi/model.py b/src/kimchi/model.py
index 2ecbc9c..73c18ac 100644
--- a/src/kimchi/model.py
+++ b/src/kimchi/model.py
@@ -1529,11 +1529,6 @@ class LibvirtConnection(object):
def wrapper(*args, **kwargs):
try:
ret = f(*args, **kwargs)
- if isinstance(ret, self.wrappables):
- for name in dir(ret):
- method = getattr(ret, name)
- if callable(method) and not name.startswith('_'):
- setattr(ret, name, wrapMethod(method))
return ret
except libvirt.libvirtError as e:
edom = e.get_error_domain()
@@ -1577,6 +1572,12 @@ class LibvirtConnection(object):
if callable(method) and not name.startswith('_'):
setattr(conn, name, wrapMethod(method))
+ for cls in self.wrappables:
+ for name in dir(cls):
+ method = getattr(cls, name)
+ if callable(method) and not name.startswith('_'):
+ setattr(cls, name, wrapMethod(method))
+
self._connections[conn_id] = conn
# In case we're running into troubles with keeping the connections
# alive we should place here:
--
1.8.3.1