Skip to content

Instantly share code, notes, and snippets.

@shivanandmn
Created May 5, 2022 20:03
Show Gist options
  • Save shivanandmn/71925915c6fd12a467c28b36ed3bf8ee to your computer and use it in GitHub Desktop.
Save shivanandmn/71925915c6fd12a467c28b36ed3bf8ee to your computer and use it in GitHub Desktop.
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