Skip to content

Instantly share code, notes, and snippets.

@staticor
Created December 20, 2018 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save staticor/f5723167532f40a55e208ed20195e575 to your computer and use it in GitHub Desktop.
Save staticor/f5723167532f40a55e208ed20195e575 to your computer and use it in GitHub Desktop.
multiprocess pool test
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