Skip to content

Commit

Permalink
backend: add --no-threads parameter for easier debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
FrostyX committed Oct 16, 2023
1 parent 7ceacf3 commit a0f6c76
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions backend/run/copr_prune_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit a0f6c76

Please sign in to comment.