Python multirpocessing.reduction在内部做什么?

时间:2016-02-02 05:17:55

标签: python python-multiprocessing

我找到了Python multiprocessing.reduction模块,同时在here中的进程之间共享文件描述符。

我的问题是,还原模块在内部做什么来在进程之间共享文件描述符。(reduce_handle()rebuild_handle()方法)

你能详细解释一下吗?

#reduction.py
def reduce_handle(handle):
    if Popen.thread_is_spawning():
        return (None, Popen.duplicate_for_child(handle), True)
    dup_handle = duplicate(handle)
    _cache.add(dup_handle)
    sub_debug('reducing handle %d', handle)
    return (_get_listener().address, dup_handle, False)

def rebuild_handle(pickled_data):
    address, handle, inherited = pickled_data
    if inherited:
        return handle
    sub_debug('rebuilding handle %d', handle)
    conn = Client(address, authkey=current_process().authkey)
    conn.send((handle, os.getpid()))
    new_handle = recv_handle(conn)
    conn.close()
    return new_handle

0 个答案:

没有答案