import os
import sys
import subprocess
proc = subprocess.Popen([sys.executable, '-c',
    'import subprocess;subprocess.Popen("sleep 5", shell=True).wait()'])
pid, status = os.waitpid(-1, 0)
print(pid, status)
Python: How to determine subprocess children have all finished running