From b5d075d04f1e555f85aad27e74f16073a50b2ae6 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 1 Mar 2021 00:56:38 -0500 Subject: command: add a helper for the parallel execution boilerplate Now that we have a bunch of subcommands doing parallel execution, a common pattern arises that we can factor out for most of them. We leave forall alone as it's a bit too complicated atm to cut over. Change-Id: I3617a4f7c66142bcd1ab030cb4cca698a65010ac Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/301942 Tested-by: Mike Frysinger Reviewed-by: Chris Mcdonald --- subcmds/status.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'subcmds/status.py') diff --git a/subcmds/status.py b/subcmds/status.py index dc223a00..1b48dcea 100644 --- a/subcmds/status.py +++ b/subcmds/status.py @@ -15,10 +15,9 @@ import functools import glob import io -import multiprocessing import os -from command import DEFAULT_LOCAL_JOBS, PagedCommand, WORKER_BATCH_SIZE +from command import DEFAULT_LOCAL_JOBS, PagedCommand from color import Coloring import platform_utils @@ -119,22 +118,23 @@ the following meanings: def Execute(self, opt, args): all_projects = self.GetProjects(args) - counter = 0 - if opt.jobs == 1: - for project in all_projects: - state = project.PrintWorkTreeStatus(quiet=opt.quiet) + def _ProcessResults(_pool, _output, results): + ret = 0 + for (state, output) in results: + if output: + print(output, end='') if state == 'CLEAN': - counter += 1 - else: - with multiprocessing.Pool(opt.jobs) as pool: - states = pool.imap(functools.partial(self._StatusHelper, opt.quiet), - all_projects, chunksize=WORKER_BATCH_SIZE) - for (state, output) in states: - if output: - print(output, end='') - if state == 'CLEAN': - counter += 1 + ret += 1 + return ret + + counter = self.ExecuteInParallel( + opt.jobs, + functools.partial(self._StatusHelper, opt.quiet), + all_projects, + callback=_ProcessResults, + ordered=True) + if not opt.quiet and len(all_projects) == counter: print('nothing to commit (working directory clean)') -- cgit v1.2.3-54-g00ecf