linker: Simplify creating pool

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ář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2018-10-01 13:08:06 +02:00
parent e2e8df3f09
commit 1aff7fc3ac
3 changed files with 11 additions and 8 deletions

View File

@ -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):

View File

@ -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"]

View File

@ -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)