summaryrefslogtreecommitdiffstats
path: root/pym/portage/__init__.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2011-06-03 18:38:40 -0700
committerZac Medico <zmedico@gentoo.org>2011-06-03 18:38:40 -0700
commiteb8325c739fdafbff6652e43f6fe8074f1f0aa28 (patch)
treea96f98317bfdc7a8944714095b0e5fa2f06d32ba /pym/portage/__init__.py
parent989fe2831c94ab1afaad8220742c80c2cbd28730 (diff)
downloadportage-eb8325c739fdafbff6652e43f6fe8074f1f0aa28.tar.gz
portage-eb8325c739fdafbff6652e43f6fe8074f1f0aa28.tar.bz2
portage-eb8325c739fdafbff6652e43f6fe8074f1f0aa28.zip
portdbapi: cleanup when base module is reloaded
This prevents memory leaks via portdbapi.portdbapi_instances when the module is reloaded. Also, there's no need for ebuild(1) to call close_portdbapi_caches() since it's now handled automatically during the reload.
Diffstat (limited to 'pym/portage/__init__.py')
-rw-r--r--pym/portage/__init__.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index 9e8298ef7..515a9a7a2 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -576,6 +576,35 @@ if VERSION == 'HEAD':
return VERSION
VERSION = _LazyVersion()
+if "_legacy_globals_constructed" in globals():
+ # The module has been reloaded, so perform any relevant cleanup
+ # and prevent memory leaks.
+ if "db" in _legacy_globals_constructed:
+ try:
+ db
+ except NameError:
+ pass
+ else:
+ if isinstance(db, dict) and db:
+ for _x in db.values():
+ try:
+ if "porttree" in _x.lazy_items:
+ continue
+ except (AttributeError, TypeError):
+ continue
+ try:
+ _x = _x["porttree"].dbapi
+ except (AttributeError, KeyError):
+ continue
+ if not isinstance(_x, portdbapi):
+ continue
+ _x.close_caches()
+ try:
+ portdbapi.portdbapi_instances.remove(_x)
+ except ValueError:
+ pass
+ del _x
+
class _LegacyGlobalProxy(proxy.objectproxy.ObjectProxy):
__slots__ = ('_name',)