diff options
Diffstat (limited to 'subcmds/checkout.py')
-rw-r--r-- | subcmds/checkout.py | 22 |
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 | ||
15 | import functools | 15 | import functools |
16 | import multiprocessing | ||
17 | import sys | 16 | import sys |
18 | 17 | ||
19 | from command import Command, DEFAULT_LOCAL_JOBS, WORKER_BATCH_SIZE | 18 | from command import Command, DEFAULT_LOCAL_JOBS |
20 | from progress import Progress | 19 | from 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: |