Created
April 17, 2019 23:35
-
-
Save lucaswiman/c6477d3c9a58ee1998f2a84944407219 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 typing import Callable, Iterable, T | |
from multiprocessing.pool import ThreadPool | |
def threaded_map(f: Callable[..., T], it: Iterable, num_threads: int) -> Iterable[T]: | |
pool = ThreadPool(num_threads) | |
try: | |
results = pool.map(f, it) | |
finally: | |
pool.close() | |
pool.join() | |
yield from results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment