Created
May 11, 2018 10:39
-
-
Save boxrick/440cad3ff9cccc813abd3cf571d458c5 to your computer and use it in GitHub Desktop.
Threaded example
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 | |
from multiprocessing import Pool | |
from time import sleep | |
list_of_numbers = list(xrange(101)) | |
def pull_role(stuff): | |
print('Sleeping ' + str(stuff)) | |
sleep(0.1) | |
if __name__ == "__main__": | |
core_count = multiprocessing.cpu_count()*2 | |
print ('calculated cores: ' + str(core_count)) | |
p = Pool(processes=core_count) | |
result = p.map(pull_role, list_of_numbers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment