summaryrefslogtreecommitdiffstats
path: root/subcmds/prune.py
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2021-03-01 00:56:38 -0500
committerMike Frysinger <vapier@google.com>2021-04-15 05:10:16 +0000
commitb5d075d04f1e555f85aad27e74f16073a50b2ae6 (patch)
treeb7342a0cd0a8d081cceb801b615bf8bbe1cc5647 /subcmds/prune.py
parentb8bf291ddbe00731d441a34cbf1ec5b5f95f401b (diff)
downloadgit-repo-b5d075d04f1e555f85aad27e74f16073a50b2ae6.tar.gz
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 <vapier@google.com> Reviewed-by: Chris Mcdonald <cjmcdonald@google.com>
Diffstat (limited to 'subcmds/prune.py')
-rw-r--r--subcmds/prune.py20
1 files changed, 8 insertions, 12 deletions
diff --git a/subcmds/prune.py b/subcmds/prune.py
index 4084c8b6..236b647f 100644
--- a/subcmds/prune.py
+++ b/subcmds/prune.py
@@ -13,10 +13,9 @@
13# limitations under the License. 13# limitations under the License.
14 14
15import itertools 15import itertools
16import multiprocessing
17 16
18from color import Coloring 17from color import Coloring
19from command import DEFAULT_LOCAL_JOBS, PagedCommand, WORKER_BATCH_SIZE 18from command import DEFAULT_LOCAL_JOBS, PagedCommand
20 19
21 20
22class Prune(PagedCommand): 21class Prune(PagedCommand):
@@ -36,18 +35,15 @@ class Prune(PagedCommand):
36 35
37 # NB: Should be able to refactor this module to display summary as results 36 # NB: Should be able to refactor this module to display summary as results
38 # come back from children. 37 # come back from children.
39 def _ProcessResults(results): 38 def _ProcessResults(_pool, _output, results):
40 return list(itertools.chain.from_iterable(results)) 39 return list(itertools.chain.from_iterable(results))
41 40
42 # NB: Multiprocessing is heavy, so don't spin it up for one job. 41 all_branches = self.ExecuteInParallel(
43 if len(projects) == 1 or opt.jobs == 1: 42 opt.jobs,
44 all_branches = _ProcessResults(self._ExecuteOne(x) for x in projects) 43 self._ExecuteOne,
45 else: 44 projects,
46 with multiprocessing.Pool(opt.jobs) as pool: 45 callback=_ProcessResults,
47 results = pool.imap( 46 ordered=True)
48 self._ExecuteOne, projects,
49 chunksize=WORKER_BATCH_SIZE)
50 all_branches = _ProcessResults(results)
51 47
52 if not all_branches: 48 if not all_branches:
53 return 49 return