I know that in Python, map is equivalent to parallel processing class of pool.map from multiprocessing module.
Is there a filter equivalent in parallel programming for Python?
-
pypi.org/project/python-parallel-collections look at the linkdılo sürücü– dılo sürücü2019-09-07 23:55:28 +00:00Commented Sep 7, 2019 at 23:55
-
This question may be a duplicate of Multiprocessing List Comprehension/FilterRolf Carlson– Rolf Carlson2022-04-09 00:00:01 +00:00Commented Apr 9, 2022 at 0:00
Add a comment
|
1 Answer
Python has most of function orientated programming paradigms that are necessary. Such as map, filter and reduce which you can find here
That being said, multiprocessing doesn't support filter because lambdas are not pickleable by default.
But you can always implement your own using functions mentioned above or reproducing them in manner that suits you using iterators, generators or list comprehension.
One of examples taken from sagemath is:
def pool_filter(pool, func, candidates):
return [c for c, keep in zip(candidates, pool.map(func, candidates)) if keep]
But it further depends on your implementation.
1 Comment
M.Zhu
There is a typo in your example.
p shall be pool