Rahul
Rahul

Reputation: 11669

In multiprocess module of python , how to find which worker process has executed the job

Is there any way to find out , which worker process among the Pool has executed a specific job .

For example,

def start_exe():
    #execute some bunch of statements 

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

Upvotes: 0

Views: 257

Answers (1)

jcollado
jcollado

Reputation: 40394

I don't see any API for that, but you can embed the name of the process that did the job in the result:

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()

Example output:

('done', 'PoolWorker-4')

Upvotes: 3

Related Questions