It seems to me in Python, there is no need to reap zombie processes.
For example, in the following code
import multiprocessing
import time
def func(msg):
time.sleep(2)
print "done " + str(msg)
if __name__ == "__main__":
for i in range(10):
p = multiprocessing.Process(target=func, args=('3'))
p.start()
print "child"+str(i)
print "parent"
time.sleep(100)
When all the child process exit, the parent process is still running and at this time, I checked the process using ps -ef
and I noticed there is no defunct process.
Does this mean that in Python, there is no need to reap zombie process?
Those processes are not actually zombies since they should terminate successfully. You could set the child processes to be deamonic so they'll terminate if the main process terminates.
After having a look to the library - especially to multiprocessing/process.py
-, I see that
Process.start()
, there is a _current_process._children.add(self)
which adds the started process to a list/set/whatever, _cleanup()
which polls and discards terminated processes, removing zombies. But that doesn't explain why your code doesn't produce zombies, as the childs wait a while befor terminating, so that the parent's start()
calls don't notice that yet.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.