use threadpool as executor
This commit is contained in:
parent
2cd073150e
commit
c85cdc91ca
1 changed files with 2 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from multiprocessing.pool import ThreadPool
|
||||||
from typing import Callable, TypeVar
|
from typing import Callable, TypeVar
|
||||||
from multiprocessing import Pool
|
|
||||||
|
|
||||||
|
|
||||||
T = TypeVar("T")
|
T = TypeVar("T")
|
||||||
|
@ -17,7 +17,7 @@ class RunStrategy:
|
||||||
class Parallel(RunStrategy):
|
class Parallel(RunStrategy):
|
||||||
procs: None | int = None
|
procs: None | int = None
|
||||||
def run_all(self, items: list[T], oper: Callable[[T], O]) -> list[O]:
|
def run_all(self, items: list[T], oper: Callable[[T], O]) -> list[O]:
|
||||||
return Pool(self.procs).map(oper, items)
|
return ThreadPool(self.procs).map(oper, items)
|
||||||
|
|
||||||
|
|
||||||
class Sequential(RunStrategy):
|
class Sequential(RunStrategy):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue