summaryrefslogtreecommitdiffstats
path: root/subcmds/start.py
diff options
context:
space:
mode:
Diffstat (limited to 'subcmds/start.py')
-rw-r--r--subcmds/start.py26
1 files changed, 10 insertions, 16 deletions
diff --git a/subcmds/start.py b/subcmds/start.py
index aa2f915a..ff2bae56 100644
--- a/subcmds/start.py
+++ b/subcmds/start.py
@@ -13,11 +13,10 @@
13# limitations under the License. 13# limitations under the License.
14 14
15import functools 15import functools
16import multiprocessing
17import os 16import os
18import sys 17import sys
19 18
20from command import Command, DEFAULT_LOCAL_JOBS, WORKER_BATCH_SIZE 19from command import Command, DEFAULT_LOCAL_JOBS
21from git_config import IsImmutable 20from git_config import IsImmutable
22from git_command import git 21from git_command import git
23import gitc_utils 22import gitc_utils
@@ -55,7 +54,7 @@ revision specified in the manifest.
55 if not git.check_ref_format('heads/%s' % nb): 54 if not git.check_ref_format('heads/%s' % nb):
56 self.OptionParser.error("'%s' is not a valid name" % nb) 55 self.OptionParser.error("'%s' is not a valid name" % nb)
57 56
58 def _ExecuteOne(self, opt, nb, project): 57 def _ExecuteOne(self, revision, nb, project):
59 """Start one project.""" 58 """Start one project."""
60 # If the current revision is immutable, such as a SHA1, a tag or 59 # If the current revision is immutable, such as a SHA1, a tag or
61 # a change, then we can't push back to it. Substitute with 60 # a change, then we can't push back to it. Substitute with
@@ -69,7 +68,7 @@ revision specified in the manifest.
69 68
70 try: 69 try:
71 ret = project.StartBranch( 70 ret = project.StartBranch(
72 nb, branch_merge=branch_merge, revision=opt.revision) 71 nb, branch_merge=branch_merge, revision=revision)
73 except Exception as e: 72 except Exception as e:
74 print('error: unable to checkout %s: %s' % (project.name, e), file=sys.stderr) 73 print('error: unable to checkout %s: %s' % (project.name, e), file=sys.stderr)
75 ret = False 74 ret = False
@@ -123,23 +122,18 @@ revision specified in the manifest.
123 pm.update() 122 pm.update()
124 pm.end() 123 pm.end()
125 124
126 def _ProcessResults(results): 125 def _ProcessResults(_pool, pm, results):
127 for (result, project) in results: 126 for (result, project) in results:
128 if not result: 127 if not result:
129 err.append(project) 128 err.append(project)
130 pm.update() 129 pm.update()
131 130
132 pm = Progress('Starting %s' % nb, len(all_projects), quiet=opt.quiet) 131 self.ExecuteInParallel(
133 # NB: Multiprocessing is heavy, so don't spin it up for one job. 132 opt.jobs,
134 if len(all_projects) == 1 or opt.jobs == 1: 133 functools.partial(self._ExecuteOne, opt.revision, nb),
135 _ProcessResults(self._ExecuteOne(opt, nb, x) for x in all_projects) 134 all_projects,
136 else: 135 callback=_ProcessResults,
137 with multiprocessing.Pool(opt.jobs) as pool: 136 output=Progress('Starting %s' % (nb,), len(all_projects), quiet=opt.quiet))
138 results = pool.imap_unordered(
139 functools.partial(self._ExecuteOne, opt, nb), all_projects,
140 chunksize=WORKER_BATCH_SIZE)
141 _ProcessResults(results)
142 pm.end()
143 137
144 if err: 138 if err:
145 for p in err: 139 for p in err: