summaryrefslogtreecommitdiffstats
path: root/subcmds/checkout.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/checkout.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/checkout.py')
-rw-r--r--subcmds/checkout.py22
1 files changed, 8 insertions, 14 deletions
diff --git a/subcmds/checkout.py b/subcmds/checkout.py
index 6b71a8fa..4d8009b1 100644
--- a/subcmds/checkout.py
+++ b/subcmds/checkout.py
@@ -13,10 +13,9 @@
13# limitations under the License. 13# limitations under the License.
14 14
15import functools 15import functools
16import multiprocessing
17import sys 16import sys
18 17
19from command import Command, DEFAULT_LOCAL_JOBS, WORKER_BATCH_SIZE 18from command import Command, DEFAULT_LOCAL_JOBS
20from progress import Progress 19from progress import Progress
21 20
22 21
@@ -50,7 +49,7 @@ The command is equivalent to:
50 success = [] 49 success = []
51 all_projects = self.GetProjects(args[1:]) 50 all_projects = self.GetProjects(args[1:])
52 51
53 def _ProcessResults(results): 52 def _ProcessResults(_pool, pm, results):
54 for status, project in results: 53 for status, project in results:
55 if status is not None: 54 if status is not None:
56 if status: 55 if status:
@@ -59,17 +58,12 @@ The command is equivalent to:
59 err.append(project) 58 err.append(project)
60 pm.update() 59 pm.update()
61 60
62 pm = Progress('Checkout %s' % nb, len(all_projects), quiet=opt.quiet) 61 self.ExecuteInParallel(
63 # NB: Multiprocessing is heavy, so don't spin it up for one job. 62 opt.jobs,
64 if len(all_projects) == 1 or opt.jobs == 1: 63 functools.partial(self._ExecuteOne, nb),
65 _ProcessResults(self._ExecuteOne(nb, x) for x in all_projects) 64 all_projects,
66 else: 65 callback=_ProcessResults,
67 with multiprocessing.Pool(opt.jobs) as pool: 66 output=Progress('Checkout %s' % (nb,), len(all_projects), quiet=opt.quiet))
68 results = pool.imap_unordered(
69 functools.partial(self._ExecuteOne, nb), all_projects,
70 chunksize=WORKER_BATCH_SIZE)
71 _ProcessResults(results)
72 pm.end()
73 67
74 if err: 68 if err:
75 for p in err: 69 for p in err: