Pass multiple parameters to concurrent.futures.Executor.map?

后端 未结 6 717
梦毁少年i
梦毁少年i 2020-12-07 17:27

The concurrent.futures.Executor.map takes a variable number of iterables from which the function given is called. How should I call it if I have a generator that pro

6条回答
  •  隐瞒了意图╮
    2020-12-07 18:13

    You can use currying to create new function via partial method in Python

    from concurrent.futures import ThreadPoolExecutor
    from functools import partial
    
    
    def some_func(param1, param2):
        # some code
    
    # currying some_func with 'a' argument is repeated
    func = partial(some_func, a)
    with ThreadPoolExecutor() as executor:
        executor.map(func, list_of_args):
        ...
    

    If you need to pass more than one the same parameters you can pass them to partial method

    func = partial(some_func, a, b, c)
    

提交回复
热议问题