diff options
Diffstat (limited to 'subcmds/forall.py')
-rw-r--r-- | subcmds/forall.py | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/subcmds/forall.py b/subcmds/forall.py index a2ccb7b6..24fec5ce 100644 --- a/subcmds/forall.py +++ b/subcmds/forall.py | |||
@@ -13,6 +13,7 @@ | |||
13 | # limitations under the License. | 13 | # limitations under the License. |
14 | 14 | ||
15 | import errno | 15 | import errno |
16 | import functools | ||
16 | import io | 17 | import io |
17 | import multiprocessing | 18 | import multiprocessing |
18 | import re | 19 | import re |
@@ -240,8 +241,8 @@ without iterating through the remaining projects. | |||
240 | config = self.manifest.manifestProject.config | 241 | config = self.manifest.manifestProject.config |
241 | with multiprocessing.Pool(opt.jobs, InitWorker) as pool: | 242 | with multiprocessing.Pool(opt.jobs, InitWorker) as pool: |
242 | results_it = pool.imap( | 243 | results_it = pool.imap( |
243 | DoWorkWrapper, | 244 | functools.partial(DoWorkWrapper, mirror, opt, cmd, shell, config), |
244 | self.ProjectArgs(projects, mirror, opt, cmd, shell, config), | 245 | enumerate(self._SerializeProject(x) for x in projects), |
245 | chunksize=WORKER_BATCH_SIZE) | 246 | chunksize=WORKER_BATCH_SIZE) |
246 | first = True | 247 | first = True |
247 | for (r, output) in results_it: | 248 | for (r, output) in results_it: |
@@ -270,21 +271,6 @@ without iterating through the remaining projects. | |||
270 | if rc != 0: | 271 | if rc != 0: |
271 | sys.exit(rc) | 272 | sys.exit(rc) |
272 | 273 | ||
273 | def ProjectArgs(self, projects, mirror, opt, cmd, shell, config): | ||
274 | for cnt, p in enumerate(projects): | ||
275 | try: | ||
276 | project = self._SerializeProject(p) | ||
277 | except Exception as e: | ||
278 | print('Project list error on project %s: %s: %s' % | ||
279 | (p.name, type(e).__name__, e), | ||
280 | file=sys.stderr) | ||
281 | return | ||
282 | except KeyboardInterrupt: | ||
283 | print('Project list interrupted', | ||
284 | file=sys.stderr) | ||
285 | return | ||
286 | yield [mirror, opt, cmd, shell, cnt, config, project] | ||
287 | |||
288 | 274 | ||
289 | class WorkerKeyboardInterrupt(Exception): | 275 | class WorkerKeyboardInterrupt(Exception): |
290 | """ Keyboard interrupt exception for worker processes. """ | 276 | """ Keyboard interrupt exception for worker processes. """ |
@@ -294,7 +280,7 @@ def InitWorker(): | |||
294 | signal.signal(signal.SIGINT, signal.SIG_IGN) | 280 | signal.signal(signal.SIGINT, signal.SIG_IGN) |
295 | 281 | ||
296 | 282 | ||
297 | def DoWorkWrapper(args): | 283 | def DoWorkWrapper(mirror, opt, cmd, shell, config, args): |
298 | """ A wrapper around the DoWork() method. | 284 | """ A wrapper around the DoWork() method. |
299 | 285 | ||
300 | Catch the KeyboardInterrupt exceptions here and re-raise them as a different, | 286 | Catch the KeyboardInterrupt exceptions here and re-raise them as a different, |
@@ -302,9 +288,9 @@ def DoWorkWrapper(args): | |||
302 | and making the parent hang indefinitely. | 288 | and making the parent hang indefinitely. |
303 | 289 | ||
304 | """ | 290 | """ |
305 | project = args.pop() | 291 | cnt, project = args |
306 | try: | 292 | try: |
307 | return DoWork(project, *args) | 293 | return DoWork(project, mirror, opt, cmd, shell, cnt, config) |
308 | except KeyboardInterrupt: | 294 | except KeyboardInterrupt: |
309 | print('%s: Worker interrupted' % project['name']) | 295 | print('%s: Worker interrupted' % project['name']) |
310 | raise WorkerKeyboardInterrupt() | 296 | raise WorkerKeyboardInterrupt() |