From a0f6c7633db771d99e030bdbb1a2f6071601f4af Mon Sep 17 00:00:00 2001 From: Jakub Kadlcik Date: Tue, 10 Oct 2023 12:38:10 +0200 Subject: [PATCH] backend: add --no-threads parameter for easier debugging --- backend/run/copr_prune_results.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/backend/run/copr_prune_results.py b/backend/run/copr_prune_results.py index 34c961201..3f3fa345b 100755 --- a/backend/run/copr_prune_results.py +++ b/backend/run/copr_prune_results.py @@ -44,6 +44,10 @@ action='store_true', help=("Also prune chroots that are inactive and we already did " "the last prunerepo there, implies --no-mtime-optimization")) +parser.add_argument( + "--no-threads", + action="store_true", + help="Don't use multiprocessing. This is useful for debugging with ipdb") def list_subdir(path): dir_names = [d for d in os.listdir(path) if os.path.isdir(os.path.join(path, d))] @@ -130,6 +134,7 @@ def __init__(self, opts, cmdline_opts=None): logger=LOG) self.mtime_optimization = True self.prune_finalized_chroots = False + self.no_threads = False self.workers = getattr(self.opts, "prune_workers", None) self.pool = multiprocessing.Pool(processes=self.workers) if cmdline_opts: @@ -141,6 +146,9 @@ def __init__(self, opts, cmdline_opts=None): # them for a very long time. self.mtime_optimization = False + if cmdline_opts.no_threads: + self.no_threads = True + def run(self): response = self.frontend_client.get("chroots-prunerepo-status") self.chroots = json.loads(response.content) @@ -268,10 +276,19 @@ def prune_project(self, project_path, username, projectdir): sub_dir_name, touched_before) continue - self.pool.apply_async(run_prunerepo, - (chroot_path, username, - projectdir, sub_dir_name, self.prune_days, - appstream)) + args = [chroot_path, username, projectdir, sub_dir_name, + self.prune_days, appstream] + self.maybe_async(run_prunerepo, args) + + def maybe_async(self, func, args): + """ + If multiprocessing support is enabled, run `func` in a separate process, + otherwise simply call the `func`. + """ + if self.no_threads: + func(*args) + else: + self.pool.apply_async(func, args) def clean_copr(path, days=DEF_DAYS, verbose=True):