|
25 | 25 | import statistics
|
26 | 26 | import subprocess
|
27 | 27 | import sys
|
28 |
| -import threading |
29 | 28 | import time
|
| 29 | +from concurrent.futures import ThreadPoolExecutor, as_completed |
30 | 30 |
|
31 | 31 |
|
32 | 32 | def heading(s: str) -> None:
|
@@ -99,39 +99,45 @@ def main() -> None:
|
99 | 99 | help="measure incremental run (fully cached)",
|
100 | 100 | )
|
101 | 101 | parser.add_argument(
|
102 |
| - "-n", |
103 |
| - metavar="NUM", |
| 102 | + "--num-runs", |
| 103 | + metavar="N", |
104 | 104 | default=15,
|
105 | 105 | type=int,
|
106 |
| - help="number of measurements to perform (default=15)", |
| 106 | + help="set number of measurements to perform (default=15)", |
| 107 | + ) |
| 108 | + parser.add_argument( |
| 109 | + "-j", |
| 110 | + metavar="N", |
| 111 | + default=8, |
| 112 | + type=int, |
| 113 | + help="set maximum number of parallel builds (default=8)", |
107 | 114 | )
|
108 | 115 | parser.add_argument("commit", nargs="+", help="git revision to measure (e.g. branch name)")
|
109 | 116 | args = parser.parse_args()
|
110 | 117 | incremental: bool = args.incremental
|
111 | 118 | commits = args.commit
|
112 |
| - num_runs: int = args.n + 1 |
| 119 | + num_runs: int = args.num_runs + 1 |
| 120 | + max_workers: int = args.j |
113 | 121 |
|
114 | 122 | if not (os.path.isdir(".git") and os.path.isdir("mypyc")):
|
115 | 123 | sys.exit("error: Run this the mypy repo root")
|
116 | 124 |
|
117 |
| - build_threads = [] |
118 | 125 | target_dirs = []
|
119 | 126 | for i, commit in enumerate(commits):
|
120 | 127 | target_dir = f"mypy.{i}.tmpdir"
|
121 | 128 | target_dirs.append(target_dir)
|
122 | 129 | clone(target_dir, commit)
|
123 |
| - t = threading.Thread(target=lambda: build_mypy(target_dir)) |
124 |
| - t.start() |
125 |
| - build_threads.append(t) |
126 | 130 |
|
127 | 131 | self_check_dir = "mypy.self.tmpdir"
|
128 | 132 | clone(self_check_dir, commits[0])
|
129 | 133 |
|
130 | 134 | heading("Compiling mypy")
|
131 | 135 | print("(This will take a while...)")
|
132 | 136 |
|
133 |
| - for t in build_threads: |
134 |
| - t.join() |
| 137 | + with ThreadPoolExecutor(max_workers=max_workers) as executor: |
| 138 | + futures = [executor.submit(build_mypy, target_dir) for target_dir in target_dirs] |
| 139 | + for future in as_completed(futures): |
| 140 | + future.result() |
135 | 141 |
|
136 | 142 | print(f"Finished compiling mypy ({len(commits)} builds)")
|
137 | 143 |
|
|
0 commit comments