Difference between Process.run() and Process.start()

后端 未结 3 1237
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-18 23:44

I am struggling to understand the difference between run() and start(). According to the documentation, run() method invokes the calla

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-19 00:17

    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.

提交回复
热议问题