Skip to content

Commit

Permalink
Add helpers.py
Browse files Browse the repository at this point in the history
  • Loading branch information
anasf97 authored Aug 16, 2023
1 parent d746a68 commit e8a6d39
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/clip/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from multiprocessing import Pool
from functools import partial


def parallelize(func, iterable, n_workers, **kwargs):
f = partial(func, **kwargs)
if n_workers > 1:
with Pool(n_workers) as p:
results = p.map(f, iterable)
else:
results = list(map(f, iterable))
return results

0 comments on commit e8a6d39

Please sign in to comment.