Skip to content

Commit 5438edd

Browse files
committed
Use threads instead of processes for parallel 'nix eval'
1 parent 54356f1 commit 5438edd

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

nixpkgs_review/nix.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
import multiprocessing as mp
2+
import concurrent.futures
33
import os
44
import shlex
55
import shutil
@@ -271,32 +271,29 @@ def nix_eval(
271271
os.unlink(attr_json.name)
272272

273273

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-
283274
def multi_system_eval(
284275
attr_names_per_system: dict[System, set[str]],
285276
allow: AllowedFeatures,
286277
nix_path: str,
287278
n_procs: int,
288279
) -> 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
300297

301298

302299
def nix_build(

0 commit comments

Comments
 (0)