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/status.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/status.py')
| -rw-r--r-- | subcmds/status.py | 32 |
1 files changed, 16 insertions, 16 deletions
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 @@ | |||
| 15 | import functools | 15 | import functools |
| 16 | import glob | 16 | import glob |
| 17 | import io | 17 | import io |
| 18 | import multiprocessing | ||
| 19 | import os | 18 | import os |
| 20 | 19 | ||
| 21 | from command import DEFAULT_LOCAL_JOBS, PagedCommand, WORKER_BATCH_SIZE | 20 | from command import DEFAULT_LOCAL_JOBS, PagedCommand |
| 22 | 21 | ||
| 23 | from color import Coloring | 22 | from color import Coloring |
| 24 | import platform_utils | 23 | import platform_utils |
| @@ -119,22 +118,23 @@ the following meanings: | |||
| 119 | 118 | ||
| 120 | def Execute(self, opt, args): | 119 | def Execute(self, opt, args): |
| 121 | all_projects = self.GetProjects(args) | 120 | all_projects = self.GetProjects(args) |
| 122 | counter = 0 | ||
| 123 | 121 | ||
| 124 | if opt.jobs == 1: | 122 | def _ProcessResults(_pool, _output, results): |
| 125 | for project in all_projects: | 123 | ret = 0 |
| 126 | state = project.PrintWorkTreeStatus(quiet=opt.quiet) | 124 | for (state, output) in results: |
| 125 | if output: | ||
| 126 | print(output, end='') | ||
| 127 | if state == 'CLEAN': | 127 | if state == 'CLEAN': |
| 128 | counter += 1 | 128 | ret += 1 |
| 129 | else: | 129 | return ret |
| 130 | with multiprocessing.Pool(opt.jobs) as pool: | 130 | |
| 131 | states = pool.imap(functools.partial(self._StatusHelper, opt.quiet), | 131 | counter = self.ExecuteInParallel( |
| 132 | all_projects, chunksize=WORKER_BATCH_SIZE) | 132 | opt.jobs, |
| 133 | for (state, output) in states: | 133 | functools.partial(self._StatusHelper, opt.quiet), |
| 134 | if output: | 134 | all_projects, |
| 135 | print(output, end='') | 135 | callback=_ProcessResults, |
| 136 | if state == 'CLEAN': | 136 | ordered=True) |
| 137 | counter += 1 | 137 | |
| 138 | if not opt.quiet and len(all_projects) == counter: | 138 | if not opt.quiet and len(all_projects) == counter: |
| 139 | print('nothing to commit (working directory clean)') | 139 | print('nothing to commit (working directory clean)') |
| 140 | 140 | ||
