Last active
December 23, 2023 00:26
-
-
Save huseinzol05/98974ae8c6c7a65d4bc0af9f5003786a to your computer and use it in GitHub Desktop.
mp.py use by malaya-speech and malaya
This file contains 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
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