Created
December 29, 2023 22:32
-
-
Save art-divin/9da60609f46417e4dbc20764cdd6dbaa to your computer and use it in GitHub Desktop.
Modified copy of apple/swift/utils/update_checkout Python script's concurrent clone function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def run_parallel(fn, pool_args, n_processes=0): | |
"""Function used to run a given closure in parallel. | |
NOTE: This function was originally located in the shell module of | |
swift_build_support and should eventually be replaced with a better | |
parallel implementation. | |
""" | |
if n_processes == 0: | |
n_processes = cpu_count() * 2 | |
results = [] | |
for args in pool_args: | |
fn(args) | |
#lk = Lock() | |
#print("Running ``%s`` with up to %d processes." % | |
# (fn.__name__, n_processes)) | |
#pool = Pool(processes=n_processes, initializer=child_init, initargs=(lk,)) | |
#results = pool.map_async(func=fn, iterable=pool_args).get(999999) | |
#pool.close() | |
#pool.join() | |
return results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment