Skip to content

Commit 4c695a7

Browse files
committed
Make it run in parallel
1 parent 97c6047 commit 4c695a7

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

tools/black_bindings.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/python3
2+
from concurrent.futures import ThreadPoolExecutor
3+
import os
24
import re
35
import subprocess
46
import sys
@@ -25,7 +27,7 @@ def transform(s):
2527
return "\n".join("//| " + line if line else "//|" for line in result) + "\n"
2628

2729

28-
for fn in sys.argv[1:]:
30+
def process_one_file(fn):
2931
with open(fn, "r", encoding="utf-8") as f:
3032
content = f.read()
3133

@@ -40,3 +42,11 @@ def transform(s):
4042

4143
with open(fn, "w", encoding="utf-8") as f:
4244
f.write("".join(newcontent))
45+
46+
47+
if __name__ == "__main__":
48+
# Use a thread pool because most processing is inside black!
49+
executor = ThreadPoolExecutor(max_workers=os.cpu_count())
50+
for fn in sys.argv[1:]:
51+
executor.submit(process_one_file, fn)
52+
executor.shutdown()

0 commit comments

Comments
 (0)