summaryrefslogtreecommitdiffstats
path: root/subcmds/forall.py
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2021-03-01 02:06:10 -0500
committerMike Frysinger <vapier@google.com>2021-03-01 15:58:06 +0000
commit819c73954f0f0d80afda86e871000e7521bfd982 (patch)
tree42b288e987d7425cf22c9226ace9bb931ece1c7c /subcmds/forall.py
parent179a242caa31ca4b96ada240fa6a6fef7509aa27 (diff)
downloadgit-repo-819c73954f0f0d80afda86e871000e7521bfd982.tar.gz
forall: simplify arg passing to worker children
The ProjectArgs function can be inlined which simplifies it quite a bit. We shouldn't need the custom exception handling here either. This also makes the next commit easier to review. Change-Id: If3be04f58c302c36a0f20b99de0f67e78beac141 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/298723 Reviewed-by: Michael Mortensen <mmortensen@google.com> Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'subcmds/forall.py')
-rw-r--r--subcmds/forall.py26
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
15import errno 15import errno
16import functools
16import io 17import io
17import multiprocessing 18import multiprocessing
18import re 19import 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
289class WorkerKeyboardInterrupt(Exception): 275class 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
297def DoWorkWrapper(args): 283def 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()