From: Cameron Dale Date: Sun, 2 Mar 2008 20:40:17 +0000 (-0800) Subject: Add cleanup to the MirrorManager for the AptPackages. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2ffad3010adfbe017ec46729a26730c67bf53945;p=quix0rs-apt-p2p.git Add cleanup to the MirrorManager for the AptPackages. --- diff --git a/apt_dht/AptPackages.py b/apt_dht/AptPackages.py index 48dd448..1cd517a 100644 --- a/apt_dht/AptPackages.py +++ b/apt_dht/AptPackages.py @@ -162,7 +162,6 @@ class AptPackages: def __del__(self): self.cleanup() - self.packages.close() def addRelease(self, cache_path, file_path): """Dirty hack until python-apt supports apt-pkg/indexrecords.h @@ -282,6 +281,8 @@ class AptPackages: def cleanup(self): """Cleanup and close any loaded caches.""" self.unload() + if self.unload_later and self.unload_later.active(): + self.unload_later.cancel() self.packages.close() def findHash(self, path): diff --git a/apt_dht/MirrorManager.py b/apt_dht/MirrorManager.py index 738fdeb..6c417b5 100644 --- a/apt_dht/MirrorManager.py +++ b/apt_dht/MirrorManager.py @@ -75,6 +75,13 @@ class MirrorManager: d.errback(MirrorError("Site Not Found")) return d + def cleanup(self): + for site in self.apt_caches.keys(): + for baseDir in self.apt_caches[site].keys(): + self.apt_caches[site][baseDir].cleanup() + del self.apt_caches[site][baseDir] + del self.apt_caches[site] + class TestMirrorManager(unittest.TestCase): """Unit tests for the mirror manager.""" @@ -180,5 +187,6 @@ class TestMirrorManager(unittest.TestCase): for p in self.pending_calls: if p.active(): p.cancel() + self.client.cleanup() self.client = None \ No newline at end of file