subprocess module in Python standard library allows you to spanw
processes to do some tasks. The parent process should
wait on its
children processes in order get the return value of the process and avoid
In theory, Python should take care of reaping zombies for you once the zombie process gets garbage collected. In practice, it does not seem to work reliably and bigger weapons are needed.
Take for example the following script:
Here I create 3 processes, without holding any references to them, wait for them to finish, and I would expect the GC to kick in and reap them when done. Instead, they are left as zombies until the parent process exits.
Forcing GC does not work either:
One way is to explicitely
Another way is to explicitly cycle over all the children of the main process
os.waitpid on them: this has the effect of removing the zombies from the