|
1 | 1 | import json |
2 | | -import multiprocessing as mp |
| 2 | +import concurrent.futures |
3 | 3 | import os |
4 | 4 | import shlex |
5 | 5 | import shutil |
@@ -271,32 +271,29 @@ def nix_eval( |
271 | 271 | os.unlink(attr_json.name) |
272 | 272 |
|
273 | 273 |
|
274 | | -def nix_eval_thread( |
275 | | - system: System, |
276 | | - attr_names: set[str], |
277 | | - allow: AllowedFeatures, |
278 | | - nix_path: str, |
279 | | -) -> tuple[System, list[Attr]]: |
280 | | - return system, nix_eval(attr_names, system, allow, nix_path) |
281 | | - |
282 | | - |
283 | 274 | def multi_system_eval( |
284 | 275 | attr_names_per_system: dict[System, set[str]], |
285 | 276 | allow: AllowedFeatures, |
286 | 277 | nix_path: str, |
287 | 278 | n_procs: int, |
288 | 279 | ) -> dict[System, list[Attr]]: |
289 | | - nix_eval_partial = partial( |
290 | | - nix_eval_thread, |
291 | | - allow=allow, |
292 | | - nix_path=nix_path, |
293 | | - ) |
294 | | - |
295 | | - args: list[tuple[System, set[str]]] = list(attr_names_per_system.items()) |
296 | | - with mp.Pool(n_procs) as pool: |
297 | | - results: list[tuple[System, list[Attr]]] = pool.starmap(nix_eval_partial, args) |
298 | | - |
299 | | - return {system: attrs for system, attrs in results} |
| 280 | + results: dict[System, list[Attr]] = {} |
| 281 | + with concurrent.futures.ThreadPoolExecutor(max_workers=n_procs) as executor: |
| 282 | + future_to_system = { |
| 283 | + executor.submit( |
| 284 | + nix_eval, |
| 285 | + attrs=attrs, |
| 286 | + system=system, |
| 287 | + allow=allow, |
| 288 | + nix_path=nix_path, |
| 289 | + ): system |
| 290 | + for system, attrs in attr_names_per_system.items() |
| 291 | + } |
| 292 | + for future in concurrent.futures.as_completed(future_to_system): |
| 293 | + system = future_to_system[future] |
| 294 | + results[system] = future.result() |
| 295 | + |
| 296 | + return results |
300 | 297 |
|
301 | 298 |
|
302 | 299 | def nix_build( |
|
0 commit comments