summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--subcmds/forall.py25
1 files changed, 10 insertions, 15 deletions
diff --git a/subcmds/forall.py b/subcmds/forall.py
index d871b3ea..b874b6d2 100644
--- a/subcmds/forall.py
+++ b/subcmds/forall.py
@@ -21,7 +21,7 @@ import sys
21import subprocess 21import subprocess
22 22
23from color import Coloring 23from color import Coloring
24from command import DEFAULT_LOCAL_JOBS, Command, MirrorSafeCommand 24from command import DEFAULT_LOCAL_JOBS, Command, MirrorSafeCommand, WORKER_BATCH_SIZE
25import platform_utils 25import platform_utils
26 26
27_CAN_COLOR = [ 27_CAN_COLOR = [
@@ -234,31 +234,26 @@ without iterating through the remaining projects.
234 234
235 os.environ['REPO_COUNT'] = str(len(projects)) 235 os.environ['REPO_COUNT'] = str(len(projects))
236 236
237 pool = multiprocessing.Pool(opt.jobs, InitWorker)
238 try: 237 try:
239 config = self.manifest.manifestProject.config 238 config = self.manifest.manifestProject.config
240 results_it = pool.imap( 239 with multiprocessing.Pool(opt.jobs, InitWorker) as pool:
241 DoWorkWrapper, 240 results_it = pool.imap(
242 self.ProjectArgs(projects, mirror, opt, cmd, shell, config)) 241 DoWorkWrapper,
243 pool.close() 242 self.ProjectArgs(projects, mirror, opt, cmd, shell, config),
244 for r in results_it: 243 chunksize=WORKER_BATCH_SIZE)
245 rc = rc or r 244 for r in results_it:
246 if r != 0 and opt.abort_on_errors: 245 rc = rc or r
247 raise Exception('Aborting due to previous error') 246 if r != 0 and opt.abort_on_errors:
247 raise Exception('Aborting due to previous error')
248 except (KeyboardInterrupt, WorkerKeyboardInterrupt): 248 except (KeyboardInterrupt, WorkerKeyboardInterrupt):
249 # Catch KeyboardInterrupt raised inside and outside of workers 249 # Catch KeyboardInterrupt raised inside and outside of workers
250 print('Interrupted - terminating the pool')
251 pool.terminate()
252 rc = rc or errno.EINTR 250 rc = rc or errno.EINTR
253 except Exception as e: 251 except Exception as e:
254 # Catch any other exceptions raised 252 # Catch any other exceptions raised
255 print('Got an error, terminating the pool: %s: %s' % 253 print('Got an error, terminating the pool: %s: %s' %
256 (type(e).__name__, e), 254 (type(e).__name__, e),
257 file=sys.stderr) 255 file=sys.stderr)
258 pool.terminate()
259 rc = rc or getattr(e, 'errno', 1) 256 rc = rc or getattr(e, 'errno', 1)
260 finally:
261 pool.join()
262 if rc != 0: 257 if rc != 0:
263 sys.exit(rc) 258 sys.exit(rc)
264 259