I am struggling to understand the difference between run()
and start()
. According to the documentation, run()
method invokes the calla
You are not supposed to call process.run()
explicitly. It's the method which invokes your specified target
function unless you override it when you subclass Process
. It normally gets called within the new child while it bootstraps. It does nothing else than calling the target function.
# multiprocessing.process.BaseProcess
def run(self):
'''
Method to be run in sub-process; can be overridden in sub-class
'''
if self._target:
self._target(*self._args, **self._kwargs)
When you call it in your parent process, it gets executed in your parent process like any other method.
process.start()
is the method which you're supposed to call in your parent to create the new process in the first place.
You're exactly right. As it describes in the docs, run()
is the entry point of the new thread created by start()
.
Invoking start()
will create a new thread and execute run()
in this new thread. Whereas, invoking run()
yourself will execute it in the current thread itself. Execution of run()
will not switch to a different thread. So it will execute its actions on the main thread itself.