Skip to content

Commit 19636e2

Browse files
salkiniumrleh
authored andcommitted
[scripts] Use ThreadPool to compile examples
1 parent c2da2cf commit 19636e2

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

tools/scripts/examples_compile.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import argparse
1414
import platform
1515
import subprocess
16-
import multiprocessing as mp
16+
from multiprocessing.pool import ThreadPool
1717
from pathlib import Path
1818

1919
is_running_in_ci = (os.getenv("CIRCLECI") is not None or
@@ -31,8 +31,8 @@ def run_command(where, command, all_output=False):
3131
result = subprocess.run(command, shell=True, cwd=where, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
3232
output = ""
3333
if result.returncode or all_output:
34-
output += result.stdout.decode("utf-8").strip(" \n")
35-
output += result.stderr.decode("utf-8").strip(" \n")
34+
output += result.stdout.decode("utf-8", errors="ignore").strip(" \n")
35+
output += result.stderr.decode("utf-8", errors="ignore").strip(" \n")
3636
return (result.returncode, output)
3737

3838
def generate(project):
@@ -108,23 +108,22 @@ def compile_examples(paths, jobs, split, part):
108108
chunk_size = math.ceil(len(projects) / args.split)
109109
projects = projects[chunk_size*args.part:min(chunk_size*(args.part+1), len(projects))]
110110

111-
ctx = mp.get_context("spawn")
112111
# first generate all projects
113-
with ctx.Pool(jobs) as pool:
112+
with ThreadPool(jobs) as pool:
114113
projects = pool.map(generate, projects)
115114
results += projects.count(None)
116115

117116
# Filter projects for successful generation
118117
projects = [p for p in projects if p is not None]
119118
# Then build the successfully generated ones
120-
with ctx.Pool(jobs) as pool:
119+
with ThreadPool(jobs) as pool:
121120
projects = pool.map(build, projects)
122121
results += projects.count(None)
123122

124123
# Filter projects for successful compilation and runablity
125124
projects = [p for p in projects if p is not None and "CI: run" in p.read_text()]
126125
# Then run the successfully compiled ones
127-
with ctx.Pool(jobs) as pool:
126+
with ThreadPool(jobs) as pool:
128127
projects = pool.map(run, projects)
129128
results += projects.count(None)
130129

0 commit comments

Comments
 (0)