OSDN Git Service

Do not use multiprocessing.Pool when --processes=1.
authorChih-Hung Hsieh <chh@google.com>
Fri, 28 Oct 2016 17:53:34 +0000 (10:53 -0700)
committerChih-Hung Hsieh <chh@google.com>
Fri, 28 Oct 2016 17:53:34 +0000 (10:53 -0700)
Purpose of this change is not to save some execution time,
but to avoid forking another process. In other applications
that use a wrapper to call this python script, it is difficult
to get overwritten file I/O functions work in a subprocess.
So the wrapper will call warn.py with --processes=1.

Test: run "warn.py --processes=1 build.log"
Change-Id: I5998d5c70d81a456c86eb4002f444a4a60135477

tools/warn.py

index 45ffda0..355d120 100755 (executable)
@@ -2096,13 +2096,17 @@ def classify_warnings(lines):
 def parallel_classify_warnings(warning_lines):
   """Classify all warning lines with num_cpu parallel processes."""
   num_cpu = args.processes
-  groups = [[] for x in range(num_cpu)]
-  i = 0
-  for x in warning_lines:
-    groups[i].append(x)
-    i = (i + 1) % num_cpu
-  pool = multiprocessing.Pool(num_cpu)
-  group_results = pool.map(classify_warnings, groups)
+  if num_cpu > 1:
+    groups = [[] for x in range(num_cpu)]
+    i = 0
+    for x in warning_lines:
+      groups[i].append(x)
+      i = (i + 1) % num_cpu
+    pool = multiprocessing.Pool(num_cpu)
+    group_results = pool.map(classify_warnings, groups)
+  else:
+    group_results = [classify_warnings(warning_lines)]
+
   for result in group_results:
     for line, pattern_idx, project_idx in result:
       pattern = warn_patterns[pattern_idx]