Last active
August 6, 2023 15:05
-
-
Save mebusw/b4cacbfc29cd64620a07 to your computer and use it in GitHub Desktop.
python multi-threading with map()
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 multiprocessing import Pool | |
import time | |
def func(i): | |
time.sleep(1) | |
print i | |
pool = Pool(3) | |
pool.map(func, range(30)) | |
pool.close() | |
pool.join() | |
# https://medium.com/building-things-on-the-internet/40e9b2b36148#66bf-f06f781cb52b | |
# http://segmentfault.com/a/1190000000414339 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can you add
cpuCount
as argument toPool()
so that it automatically sets the maximum number of threads the system can handle at once.