Created
May 5, 2022 20:03
-
-
Save shivanandmn/71925915c6fd12a467c28b36ed3bf8ee to your computer and use it in GitHub Desktop.
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 concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor | |
from tqdm import tqdm | |
def concurrency(function,data,length,method="thread"): | |
if method=="thread": | |
print("Mode :",method) | |
with ThreadPoolExecutor() as pe: | |
res = list(tqdm(pe.map(function,data),total=length)) | |
return res | |
elif method=="process": | |
print("Mode :",method) | |
with ProcessPoolExecutor() as pe: | |
res = list(tqdm(pe.map(function,data),total=length)) | |
return res | |
else: | |
print("ERROR") | |
raise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment