diff options
author | Michał Górny <mgorny@gentoo.org> | 2017-12-02 20:50:59 +0100 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2017-12-02 20:50:59 +0100 |
commit | b26e4261da01d33960f569f8105621ee714e6b5b (patch) | |
tree | bb1dac65c988ea7e6460d5391e4ce355d1776b24 | |
parent | 8b98aabe1bcc696114c07e8befc112bfecdf7e72 (diff) | |
download | gemato-b26e4261da01d33960f569f8105621ee714e6b5b.tar.gz |
Use try..finally to ensure that Pool is always terminated
-rw-r--r-- | gemato/recursiveloader.py | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/gemato/recursiveloader.py b/gemato/recursiveloader.py index 132115f..baa7c24 100644 --- a/gemato/recursiveloader.py +++ b/gemato/recursiveloader.py @@ -300,34 +300,36 @@ class ManifestRecursiveLoader(object): pool = multiprocessing.Pool(processes=self.max_jobs) - # TODO: figure out how to avoid confusing uses of 'recursive' - while True: - to_load = [] - for curmpath, relpath, m in self._iter_manifests_for_path( - path, recursive): - for e in m.entries: - if e.tag != 'MANIFEST': - continue - mpath = os.path.join(relpath, e.path) - if curmpath == mpath or mpath in self.loaded_manifests: - continue - mdir = os.path.dirname(mpath) - if not verify: - e = None - if gemato.util.path_starts_with(path, mdir): - to_load.append((mpath, e)) - elif recursive and gemato.util.path_starts_with(mdir, path): - to_load.append((mpath, e)) - if not to_load: - break - - manifests = pool.imap_unordered(self.manifest_loader, to_load, - chunksize=16) - self.loaded_manifests.update(manifests) - - pool.close() - pool.join() - pool.terminate() + try: + # TODO: figure out how to avoid confusing uses of 'recursive' + while True: + to_load = [] + for curmpath, relpath, m in self._iter_manifests_for_path( + path, recursive): + for e in m.entries: + if e.tag != 'MANIFEST': + continue + mpath = os.path.join(relpath, e.path) + if curmpath == mpath or mpath in self.loaded_manifests: + continue + mdir = os.path.dirname(mpath) + if not verify: + e = None + if gemato.util.path_starts_with(path, mdir): + to_load.append((mpath, e)) + elif recursive and gemato.util.path_starts_with(mdir, path): + to_load.append((mpath, e)) + if not to_load: + break + + manifests = pool.imap_unordered(self.manifest_loader, to_load, + chunksize=16) + self.loaded_manifests.update(manifests) + + pool.close() + pool.join() + finally: + pool.terminate() def find_timestamp(self): """ |