Created
December 20, 2018 15:29
-
-
Save staticor/f5723167532f40a55e208ed20195e575 to your computer and use it in GitHub Desktop.
multiprocess pool test
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
import multiprocessing as mp | |
def job(x): | |
return x * x | |
pool = mp.Pool() | |
res = pool.map(job, range(10)) | |
def multicore(): | |
pool = mp.Pool() | |
res = pool.map(job, range(10)) | |
print(res) | |
def multicore(): | |
pool = mp.Pool(processes=3) # 定义CPU核数量为3 | |
res = pool.map(job, range(10)) | |
print(res) | |
if __name__ == '__main__': | |
multicore() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment