[projects/pld-ftp-admin] ftptree: stop the header readers before waiting for them
arekm
arekm at pld-linux.org
Thu Oct 29 09:17:40 CET 2026
commit 7c523f558c22f341dca786a9fe31ac8dc5f998b6
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Thu Oct 29 00:09:05 2026 +0100
ftptree: stop the header readers before waiting for them
The processes that read rpm headers for the move checks ignore Ctrl-C,
so that only the script stops. On Ctrl-C, or any other error, the
script waited for the pool to shut down, and so for every read in
progress, and stopped the processes only then. A read that never ends,
such as of a FIFO in place of an rpm, hung the script on Ctrl-C, and
its trees stayed locked.
The processes are now stopped first, then the pool is shut down.
modules/ftptree.py | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
---
diff --git a/modules/ftptree.py b/modules/ftptree.py
index ac83d1c..06bd2b2 100644
--- a/modules/ftptree.py
+++ b/modules/ftptree.py
@@ -501,17 +501,20 @@ class FtpTree(BaseFtpTree):
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:
- # not spawn or forkserver: the scripts have no __main__ guard, so they would run again
- with concurrent.futures.ProcessPoolExecutor(workers, mp_context=multiprocessing.get_context('fork'),
- initializer=_start_reader) as pool:
- self.__rpmcache.update(zip(todo, pool.map(_read_rpm, todo, chunksize=READ_CHUNK)))
- finally:
- # a pool stopped while it starts (Ctrl-C, no room for more processes) leaves the
- # processes it started waiting for work, and the exit waiting for them
+ 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()
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