在python的多进程模块中,如何找到哪个工作进程执行了作业

在python的多进程模块中,如何找到哪个工作进程执行了作业,python,multiprocessing,Python,Multiprocessing,有没有办法找出池中的哪个工作进程执行了特定的作业 比如说, def start_exe(): #execute some bunch of statements if __name__ == '__main__': p = Pool(5) result = p.apply.async(start_exe) print result.get() 我没有看到任何API,但您可以在结果中嵌入执行作业的进程的名称: from multiprocessing impo

有没有办法找出池中的哪个工作进程执行了特定的作业

比如说,

def start_exe():
    #execute some bunch of statements 

if __name__ == '__main__':
    p = Pool(5)
    result = p.apply.async(start_exe)
    print result.get()

我没有看到任何API,但您可以在结果中嵌入执行作业的进程的名称:

from multiprocessing import Pool, current_process

def start_exe():
    return 'done', current_process().name

if __name__ == '__main__':
    p = Pool(5)
    result = p.apply_async(start_exe)

    print result.get()
示例输出:

('done', 'PoolWorker-4')

我没有看到任何API,但您可以在结果中嵌入执行作业的进程的名称:

from multiprocessing import Pool, current_process

def start_exe():
    return 'done', current_process().name

if __name__ == '__main__':
    p = Pool(5)
    result = p.apply_async(start_exe)

    print result.get()
示例输出:

('done', 'PoolWorker-4')