Python Multiprocessing.Process: Start With Local Variable
Solution 1:
From Python: Essential Reference by Beazley:
p.run(): The method that runs when the process starts. By default, this invokes target that was passed to the Process constructor. ...
p.start(): Starts the process. This launches the subprocess that represents the process and invokes p.run() in that subprocess.
So, they are not meant to be doing the same thing. It looks to me like in this case, p.run() is being invoked for the ongoing process and p.start() calls p.run() in a new process with the original target that was passed to the constructor (in which l is [ ] still).
Solution 2:
Run executes the callable object that you target in multiprocessing. Start will call the run() method for the object.
From multiprocessing's documentation
run() Method representing the process’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
start() Start the process’s activity.
This must be called at most once per process object. It arranges for the object’s run() method to be invoked in a separate process.
Post a Comment for "Python Multiprocessing.Process: Start With Local Variable"