diff options
author | Mike Frysinger <vapier@google.com> | 2021-03-01 00:56:38 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2021-04-15 05:10:16 +0000 |
commit | b5d075d04f1e555f85aad27e74f16073a50b2ae6 (patch) | |
tree | b7342a0cd0a8d081cceb801b615bf8bbe1cc5647 /subcmds/branches.py | |
parent | b8bf291ddbe00731d441a34cbf1ec5b5f95f401b (diff) | |
download | git-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/branches.py')
-rw-r--r-- | subcmds/branches.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/subcmds/branches.py b/subcmds/branches.py index d5ea580c..2dc102bb 100644 --- a/subcmds/branches.py +++ b/subcmds/branches.py | |||
@@ -13,10 +13,10 @@ | |||
13 | # limitations under the License. | 13 | # limitations under the License. |
14 | 14 | ||
15 | import itertools | 15 | import itertools |
16 | import multiprocessing | ||
17 | import sys | 16 | import sys |
17 | |||
18 | from color import Coloring | 18 | from color import Coloring |
19 | from command import Command, DEFAULT_LOCAL_JOBS, WORKER_BATCH_SIZE | 19 | from command import Command, DEFAULT_LOCAL_JOBS |
20 | 20 | ||
21 | 21 | ||
22 | class BranchColoring(Coloring): | 22 | class BranchColoring(Coloring): |
@@ -102,15 +102,19 @@ is shown, then the branch appears in all projects. | |||
102 | out = BranchColoring(self.manifest.manifestProject.config) | 102 | out = BranchColoring(self.manifest.manifestProject.config) |
103 | all_branches = {} | 103 | all_branches = {} |
104 | project_cnt = len(projects) | 104 | project_cnt = len(projects) |
105 | with multiprocessing.Pool(processes=opt.jobs) as pool: | ||
106 | project_branches = pool.imap_unordered( | ||
107 | expand_project_to_branches, projects, chunksize=WORKER_BATCH_SIZE) | ||
108 | 105 | ||
109 | for name, b in itertools.chain.from_iterable(project_branches): | 106 | def _ProcessResults(_pool, _output, results): |
107 | for name, b in itertools.chain.from_iterable(results): | ||
110 | if name not in all_branches: | 108 | if name not in all_branches: |
111 | all_branches[name] = BranchInfo(name) | 109 | all_branches[name] = BranchInfo(name) |
112 | all_branches[name].add(b) | 110 | all_branches[name].add(b) |
113 | 111 | ||
112 | self.ExecuteInParallel( | ||
113 | opt.jobs, | ||
114 | expand_project_to_branches, | ||
115 | projects, | ||
116 | callback=_ProcessResults) | ||
117 | |||
114 | names = sorted(all_branches) | 118 | names = sorted(all_branches) |
115 | 119 | ||
116 | if not names: | 120 | if not names: |