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:
parent
e2e8df3f09
commit
1aff7fc3ac
@ -31,6 +31,13 @@ class LinkerPool(ThreadPool):
|
|||||||
self.link_type = link_type
|
self.link_type = link_type
|
||||||
self.linker = Linker()
|
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):
|
class LinkerThread(WorkerThread):
|
||||||
def process(self, item, num):
|
def process(self, item, num):
|
||||||
|
@ -18,7 +18,7 @@ import os
|
|||||||
|
|
||||||
import kobo.rpmlib
|
import kobo.rpmlib
|
||||||
|
|
||||||
from pungi.linker import LinkerThread, LinkerPool
|
from pungi.linker import LinkerPool
|
||||||
|
|
||||||
|
|
||||||
# TODO: global Linker instance - to keep hardlinks on dest?
|
# 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)
|
compose.log_info("[BEGIN] %s" % msg)
|
||||||
link_type = compose.conf["link_type"]
|
link_type = compose.conf["link_type"]
|
||||||
|
|
||||||
pool = LinkerPool(link_type, logger=compose._logger)
|
pool = LinkerPool.with_workers(10, link_type, logger=compose._logger)
|
||||||
for i in range(10):
|
|
||||||
pool.add(LinkerThread(pool))
|
|
||||||
|
|
||||||
hashed_directories = compose.conf["hashed_directories"]
|
hashed_directories = compose.conf["hashed_directories"]
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ from pungi.phases.pkgset.common import (run_create_global_repo,
|
|||||||
create_arch_repos,
|
create_arch_repos,
|
||||||
populate_arch_pkgsets)
|
populate_arch_pkgsets)
|
||||||
from pungi.phases.gather import get_prepopulate_packages, get_packages_to_gather
|
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
|
import pungi.phases.pkgset.source
|
||||||
@ -52,9 +52,7 @@ def get_pkgset_from_repos(compose):
|
|||||||
profiler = compose.conf["gather_profiler"]
|
profiler = compose.conf["gather_profiler"]
|
||||||
|
|
||||||
link_type = compose.conf["link_type"]
|
link_type = compose.conf["link_type"]
|
||||||
pool = LinkerPool(link_type, logger=compose._logger)
|
pool = LinkerPool.with_workers(10, link_type, logger=compose._logger)
|
||||||
for i in range(10):
|
|
||||||
pool.add(LinkerThread(pool))
|
|
||||||
|
|
||||||
path_prefix = os.path.join(compose.paths.work.topdir(arch="global"), "download") + "/"
|
path_prefix = os.path.join(compose.paths.work.topdir(arch="global"), "download") + "/"
|
||||||
makedirs(path_prefix)
|
makedirs(path_prefix)
|
||||||
|
Loading…
Reference in New Issue
Block a user