functools.partial
类似装饰器,可以扩展函数的功能,将某些参数设定为固定值。
1 2 3 4 5 6
| 类func = functools.partial(func, *args, **keywords)
|
Example from Montage
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| from multiprocessing import Pool pool = Pool(conf.num_proc, init_worker)
def exec_func(js_path, conf): pass
pool_map(pool, exec_func, js_list, conf=conf)
def pool_map(pool, func, list, **args): try: func = partial(func, **args) return pool.map(func, list) except KeyboardInterrupt: pass
|