Is there a simple process-based parallel map for python?

前端 未结 4 1252
小蘑菇
小蘑菇 2020-11-29 18:50

I\'m looking for a simple process-based parallel map for python, that is, a function

parmap(function,[data])

that would run function on eac

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 19:49

    I know this is an old post, but just in case, I wrote a tool to make this super, super easy called parmapper (I actually call it parmap in my use but the name was taken).

    It handles a lot of the setup and deconstruction of processes and adds tons of features. In rough order of importance

    • Can take lambda and other unpickleable functions
    • Can apply starmap and other similar call methods to make it very easy to directly use.
    • Can split amongst both threads and/or processes
    • Includes features such as progress bars

    It does incur a small cost but for most uses, that is negligible.

    I hope you find it useful.

    (Note: It, like map in Python 3+, returns an iterable so if you expect all results to pass through it immediately, use list())

提交回复
热议问题