将多个函数传递给回调

pass more than one function to a callback

鉴于:

with concurrent.futures.ProcessPoolExecutor(max_workers=(2*multiprocessing.cpu_count()+1)) as executor:
        for netelement in DOC['code']['info']['dev']:
            job = executor.submit(bgp_communities.do_lookup, netelement)
            job.add_done_callback(functools.partial(bgp_communities.do_data_wrangling, DOC))

是否可以将第二个函数(如 bgp_communities.do_data_wrangling)作为参数传递给 future 的回调?

你的问题不是很清楚。但是,如果您希望在作业完成时调用多个函数,只需再次调用 job.add_done_callback.

with concurrent.futures.ProcessPoolExecutor(max_workers=(2*multiprocessing.cpu_count()+1)) as executor:
    for netelement in DOC['code']['info']['dev']:
        job = executor.submit(bgp_communities.do_lookup, netelement)
        job.add_done_callback(functools.partial(bgp_communities.do_data_wrangling, DOC))
        job.add_done_callback(...)

查看 docs:

add_done_callback(fn)

Attaches the callable fn to the future. fn will be called, with the future as its only argument, when the future is cancelled or finishes running.

Added callables are called in the order that they were added and are always called in a thread belonging to the process that added them. If the callable raises an Exception subclass, it will be logged and ignored. If the callable raises a BaseException subclass, the behavior is undefined.

If the future has already completed or been cancelled, fn will be called immediately.