Skip to content

Commit

Permalink
[scripts] Use ThreadPool to compile examples
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed May 6, 2023
1 parent 36ae33f commit d047f6e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions tools/scripts/examples_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import argparse
import platform
import subprocess
import multiprocessing as mp
from multiprocessing.pool import ThreadPool
from pathlib import Path

is_running_in_ci = (os.getenv("CIRCLECI") is not None or
Expand Down Expand Up @@ -108,23 +108,22 @@ def compile_examples(paths, jobs, split, part):
chunk_size = math.ceil(len(projects) / args.split)
projects = projects[chunk_size*args.part:min(chunk_size*(args.part+1), len(projects))]

ctx = mp.get_context("spawn")
# first generate all projects
with ctx.Pool(jobs) as pool:
with ThreadPool(jobs) as pool:
projects = pool.map(generate, projects)
results += projects.count(None)

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

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

Expand Down

0 comments on commit d047f6e

Please sign in to comment.