How to let Pool.map take a lambda function

前端 未结 4 1618
甜味超标
甜味超标 2020-12-01 07:27

I have the following function:

def copy_file(source_file, target_dir):
    pass

Now I would like to use multiprocessing to exe

4条回答
  •  无人及你
    2020-12-01 07:46

    Use a function object:

    class Copier(object):
        def __init__(self, tgtdir):
            self.target_dir = tgtdir
        def __call__(self, src):
            copy_file(src, self.target_dir)
    

    To run your Pool.map:

    p.map(Copier(target_dir), file_list)
    

提交回复
热议问题