Skip to content

Instantly share code, notes, and snippets.

@huseinzol05
Last active December 23, 2023 00:26
Show Gist options
  • Save huseinzol05/98974ae8c6c7a65d4bc0af9f5003786a to your computer and use it in GitHub Desktop.
Save huseinzol05/98974ae8c6c7a65d4bc0af9f5003786a to your computer and use it in GitHub Desktop.
mp.py use by malaya-speech and malaya
from multiprocess import Pool
import itertools
def chunks(l, n):
for i in range(0, len(l), n):
yield (l[i: i + n], i // n)
def multiprocessing(strings, function, cores=6, returned=True):
df_split = chunks(strings, len(strings) // cores)
pool = Pool(cores)
pooled = pool.map(function, df_split)
pool.close()
pool.join()
if returned:
return list(itertools.chain(*pooled))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment