python multiprocessing - access the process name inside the function called with Process.start(target=func)
You can use the current_process
function:
from multiprocessing import Process, current_process
def somefunc():
print current_process().name
if __name__ == '__main__':
p = Process(target=somefunc)
p.start()
print p.name
Instead of passing target
argument, override the run
method. From there, you can invoke someFunc
and pass the process object to it.
The name is not an OS level concept. It is Python level and it is not automatic that the process you execute in even has a Process
object anywhere.