[projects/pld-ftp-admin] ftptree: read rpm headers in parallel outside a tree too
arekm
arekm at pld-linux.org
Thu Oct 29 09:17:56 CET 2026
commit c48418160336c013ace7f4b93f4afb4cd0e3fd4d
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Wed Oct 28 21:44:53 2026 +0100
ftptree: read rpm headers in parallel outside a tree too
read_rpms() is the parallel read of the move checks, apart from the
tree: it gives the information of each rpm file in turn, so that a
caller can show its progress. No change for the move checks.
modules/ftptree.py | 44 +++++++++++++++++++++++++++-----------------
1 file changed, 27 insertions(+), 17 deletions(-)
---
diff --git a/modules/ftptree.py b/modules/ftptree.py
index 06bd2b2..bfe4058 100644
--- a/modules/ftptree.py
+++ b/modules/ftptree.py
@@ -44,6 +44,30 @@ def _read_rpm(path):
os.close(fdno)
return RpmInfo(signed_by_key(hdr), hdr[rpm.RPMTAG_NAME], list(hdr[rpm.RPMTAG_OBSOLETES]), None)
+def read_rpms(paths):
+ """RpmInfo of each of paths in turn (None for a missing file), read by a pool of processes
+
+ The pool stops when the last one is taken, or when the generator is closed.
+ """
+ if not paths:
+ return
+ # with fork the pool starts all its processes at once, so no more than there are tasks
+ workers = min(len(os.sched_getaffinity(0)), -(-len(paths) // READ_CHUNK))
+ # not spawn or forkserver: the scripts have no __main__ guard, so they would run again
+ pool = concurrent.futures.ProcessPoolExecutor(workers, mp_context=multiprocessing.get_context('fork'),
+ initializer=_start_reader)
+ try:
+ yield from pool.map(_read_rpm, paths, chunksize=READ_CHUNK)
+ except BaseException:
+ # the shutdown waits for the processes, which ignore Ctrl-C: for work when the pool stopped
+ # while it started (Ctrl-C, no room for more processes), for their reads otherwise
+ for p in multiprocessing.active_children():
+ p.terminate()
+ p.join()
+ raise
+ finally:
+ pool.shutdown()
+
class SomeError(Exception):
def __init__(self):
return
@@ -498,23 +522,9 @@ class FtpTree(BaseFtpTree):
def __rpminfo(self, pkgs):
"""RpmInfo of every rpm file of pkgs (None for a missing one), read in parallel"""
todo = [f for f in dict.fromkeys(f for pkg in pkgs for f in pkg.rpmfiles()) if f not in self.__rpmcache]
- if todo:
- # with fork the pool starts all its processes at once, so no more than there are tasks
- workers = min(len(os.sched_getaffinity(0)), -(-len(todo) // READ_CHUNK))
- # not spawn or forkserver: the scripts have no __main__ guard, so they would run again
- pool = concurrent.futures.ProcessPoolExecutor(workers, mp_context=multiprocessing.get_context('fork'),
- initializer=_start_reader)
- try:
- self.__rpmcache.update(zip(todo, pool.map(_read_rpm, todo, chunksize=READ_CHUNK)))
- except BaseException:
- # the shutdown waits for the processes, which ignore Ctrl-C: for work when the pool stopped
- # while it started (Ctrl-C, no room for more processes), for their reads otherwise
- for p in multiprocessing.active_children():
- p.terminate()
- p.join()
- raise
- finally:
- pool.shutdown()
+ # strict takes the end of read_rpms() too, so its pool stops here: when the generator is destroyed
+ # instead, an exception there, such as from Ctrl-C, is only printed and the move goes on
+ self.__rpmcache.update(zip(todo, read_rpms(todo), strict=True))
return self.__rpmcache
def __checksigns(self, tree, pkgs, test = False):
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/projects/pld-ftp-admin.git/commitdiff/16c6c5f2d4269aef64813afc632c36b5ce242afa
More information about the pld-cvs-commit
mailing list