From 1aff7fc3ac163253f7f7156bf8a8729c60ff0879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Mon, 1 Oct 2018 13:08:06 +0200 Subject: [PATCH] linker: Simplify creating pool MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The pool is created in multiple places, and the process is always to create an instance and add workers to it. Let's abstract the loop in a method. Signed-off-by: Lubomír Sedlář --- pungi/linker.py | 7 +++++++ pungi/phases/gather/link.py | 6 ++---- pungi/phases/pkgset/sources/source_repos.py | 6 ++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pungi/linker.py b/pungi/linker.py index 936f6f1f..d90c4fc0 100644 --- a/pungi/linker.py +++ b/pungi/linker.py @@ -31,6 +31,13 @@ class LinkerPool(ThreadPool): self.link_type = link_type self.linker = Linker() + @classmethod + def with_workers(cls, num_workers, *args, **kwargs): + pool = cls(*args, **kwargs) + for _ in range(num_workers): + pool.add(LinkerThread(pool)) + return pool + class LinkerThread(WorkerThread): def process(self, item, num): diff --git a/pungi/phases/gather/link.py b/pungi/phases/gather/link.py index 29921654..4931c6cd 100644 --- a/pungi/phases/gather/link.py +++ b/pungi/phases/gather/link.py @@ -18,7 +18,7 @@ import os import kobo.rpmlib -from pungi.linker import LinkerThread, LinkerPool +from pungi.linker import LinkerPool # TODO: global Linker instance - to keep hardlinks on dest? @@ -61,9 +61,7 @@ def link_files(compose, arch, variant, pkg_map, pkg_sets, manifest, srpm_map={}) compose.log_info("[BEGIN] %s" % msg) link_type = compose.conf["link_type"] - pool = LinkerPool(link_type, logger=compose._logger) - for i in range(10): - pool.add(LinkerThread(pool)) + pool = LinkerPool.with_workers(10, link_type, logger=compose._logger) hashed_directories = compose.conf["hashed_directories"] diff --git a/pungi/phases/pkgset/sources/source_repos.py b/pungi/phases/pkgset/sources/source_repos.py index 55aab529..50edb7f5 100644 --- a/pungi/phases/pkgset/sources/source_repos.py +++ b/pungi/phases/pkgset/sources/source_repos.py @@ -30,7 +30,7 @@ from pungi.phases.pkgset.common import (run_create_global_repo, create_arch_repos, populate_arch_pkgsets) from pungi.phases.gather import get_prepopulate_packages, get_packages_to_gather -from pungi.linker import LinkerThread, LinkerPool +from pungi.linker import LinkerPool import pungi.phases.pkgset.source @@ -52,9 +52,7 @@ def get_pkgset_from_repos(compose): profiler = compose.conf["gather_profiler"] link_type = compose.conf["link_type"] - pool = LinkerPool(link_type, logger=compose._logger) - for i in range(10): - pool.add(LinkerThread(pool)) + pool = LinkerPool.with_workers(10, link_type, logger=compose._logger) path_prefix = os.path.join(compose.paths.work.topdir(arch="global"), "download") + "/" makedirs(path_prefix)