Skip to content

Instantly share code, notes, and snippets.

Created Jan 8, 2022
What would you like to do?
processes = 20 # using 20 processes since I'm running this on my server
with Pool(processes) as p: # create the pool
print(f"Determining square values.")
# spawn the processes for each Latin square (lines is a list of strings representing the squares)
results =, lines)
print(f"Aggregating results.")
# determine how to split up the resulting (square, value) pairs [i.e. how many per process]
values_per_list = int(len(results)/processes)
extra = len(results) - (values_per_list*processes)
result_lists = []
# break the list up into smaller lists for each process
for i in range(processes-1):
# give the last process all of the remaining squares
# get all of the dictionaries returned by the build_dict function, this will be a list of dictionaries
union_dicts =, result_lists)
# combine each dictionary into one dictionary, namely 'totals'
for d in union_dicts:
totals = {**totals, **d}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment