From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 645CC1381F3 for ; Sat, 8 Jun 2013 11:09:16 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id EE932E087D; Sat, 8 Jun 2013 11:09:11 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 74F59E087D for ; Sat, 8 Jun 2013 11:09:11 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 6A15133E63A for ; Sat, 8 Jun 2013 11:09:10 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 06E3DE468F for ; Sat, 8 Jun 2013 11:09:09 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1370689727.1c9627e3749553a792de609c7931d17930738aed.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/tests/resolver/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/dbapi/porttree.py pym/portage/tests/resolver/ResolverPlayground.py X-VCS-Directories: pym/portage/dbapi/ pym/portage/tests/resolver/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 1c9627e3749553a792de609c7931d17930738aed X-VCS-Branch: master Date: Sat, 8 Jun 2013 11:09:09 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 7602c757-fe6a-4a39-9589-096257a19f60 X-Archives-Hash: 9c536a2fd05dda3b8b5a525ca8bf96c4 commit: 1c9627e3749553a792de609c7931d17930738aed Author: Zac Medico gentoo org> AuthorDate: Sat Jun 8 11:08:47 2013 +0000 Commit: Zac Medico gentoo org> CommitDate: Sat Jun 8 11:08:47 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=1c9627e3 close_portdbapi_caches: portage.db atexit hook The python interpreter does _not_ guarantee that destructors are called for objects that remain when the interpreter exits, so we use an atexit hook to call destructors for any global portdbapi instances that may have been constructed. --- pym/portage/dbapi/porttree.py | 37 +++++++++++++++++++++--- pym/portage/tests/resolver/ResolverPlayground.py | 3 ++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py index b106de7..fc3fc03 100644 --- a/pym/portage/dbapi/porttree.py +++ b/pym/portage/dbapi/porttree.py @@ -53,6 +53,39 @@ if sys.hexversion >= 0x3000000: basestring = str long = int +def close_portdbapi_caches(): + # The python interpreter does _not_ guarantee that destructors are + # called for objects that remain when the interpreter exits, so we + # use an atexit hook to call destructors for any global portdbapi + # instances that may have been constructed. + try: + portage._legacy_globals_constructed + except AttributeError: + pass + else: + if "db" in portage._legacy_globals_constructed: + try: + db = portage.db + except AttributeError: + pass + else: + if isinstance(db, dict): + for x in db.values(): + try: + if "porttree" in x.lazy_items: + continue + except (AttributeError, TypeError): + continue + try: + x = x.pop("porttree").dbapi + except (AttributeError, KeyError): + continue + if not isinstance(x, portdbapi): + continue + x.close_caches() + +portage.process.atexit_register(close_portdbapi_caches) + # It used to be necessary for API consumers to remove portdbapi instances # from portdbapi_instances, in order to avoid having accumulated instances # consume memory. Now, portdbapi_instances is just an empty dummy list, so @@ -67,10 +100,6 @@ class _dummy_list(list): except ValueError: pass -def close_portdbapi_caches(): - # Since portdbapi_instances is a dummy list, there's nothing to do here. - pass - class portdbapi(dbapi): """this tree will scan a portage directory located at root (passed to init)""" portdbapi_instances = _dummy_list() diff --git a/pym/portage/tests/resolver/ResolverPlayground.py b/pym/portage/tests/resolver/ResolverPlayground.py index 15ef95d..bff4512 100644 --- a/pym/portage/tests/resolver/ResolverPlayground.py +++ b/pym/portage/tests/resolver/ResolverPlayground.py @@ -544,6 +544,9 @@ class ResolverPlayground(object): return def cleanup(self): + for eroot in self.trees: + portdb = self.trees[eroot]["porttree"].dbapi + portdb.close_caches() if self.debug: print("\nEROOT=%s" % self.eroot) else: