From b5e88117bf4ed0aec3ab537f8f280a15b050e40c Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 11 Feb 2013 01:38:58 -0800 Subject: [PATCH] ebuild: add _reset_legacy_globals for reload This avoids weird issues that are triggered when the module is reloaded (like having classes redefined while instances from the old classes are still around, triggering TypeError confusion). --- bin/ebuild | 3 +-- pym/portage/__init__.py | 31 ++++++++++++++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/bin/ebuild b/bin/ebuild index 44b3c99d0..1ce4c9c80 100755 --- a/bin/ebuild +++ b/bin/ebuild @@ -35,7 +35,6 @@ else: signal.signal(debug_signum, debug_signal) -import imp import io import optparse import os @@ -157,7 +156,7 @@ if ebuild_portdir != vdb_path and \ encoding=_encodings['content'], errors='strict') print("Appending %s to PORTDIR_OVERLAY..." % ebuild_portdir) - imp.reload(portage) + portage._reset_legacy_globals() myrepo = None if ebuild_portdir != vdb_path: diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index a8b692c1d..bc14bae38 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -657,10 +657,17 @@ 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: +_legacy_global_var_names = ("archlist", "db", "features", + "groups", "mtimedb", "mtimedbfile", "pkglines", + "portdb", "profiledir", "root", "selinux_enabled", + "settings", "thirdpartymirrors") + +def _reset_legacy_globals(): + + global _legacy_globals_constructed + + if "_legacy_globals_constructed" in globals() and \ + "db" in _legacy_globals_constructed: try: db except NameError: @@ -684,7 +691,10 @@ if "_legacy_globals_constructed" in globals(): portdbapi.portdbapi_instances.remove(_x) except ValueError: pass - del _x + + _legacy_globals_constructed = set() + for k in _legacy_global_var_names: + globals()[k] = _LegacyGlobalProxy(k) class _LegacyGlobalProxy(proxy.objectproxy.ObjectProxy): @@ -699,16 +709,7 @@ class _LegacyGlobalProxy(proxy.objectproxy.ObjectProxy): from portage._legacy_globals import _get_legacy_global return _get_legacy_global(name) -_legacy_global_var_names = ("archlist", "db", "features", - "groups", "mtimedb", "mtimedbfile", "pkglines", - "portdb", "profiledir", "root", "selinux_enabled", - "settings", "thirdpartymirrors") - -for k in _legacy_global_var_names: - globals()[k] = _LegacyGlobalProxy(k) -del k - -_legacy_globals_constructed = set() +_reset_legacy_globals() def _disable_legacy_globals(): """ -- 2.26.2