Created
February 26, 2020 18:40
-
-
Save AdrianAcala/32194a48c921a68405228dfaf9092d0f to your computer and use it in GitHub Desktop.
Python multithreading pool example
This file contains hidden or 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 | |
def func(x): | |
print(x*x) | |
num_of_workers = multiprocessing.cpu_count() | |
pool = multiprocessing.Pool(num_of_workers) | |
for i in range(1,10): | |
pool.apply_async(func, args=(i,)) | |
pool.close() | |
pool.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment