process - Python; popen do not pass std* -


i have chain of 3 processes: process calls b spawn c, b dies. can call b "bridge" between 2 systems , c.

i want make sure c not inherit file descriptors opens in order prevent zombying, observing (sometimes calls b kill c, , after this, seeing defunct c processes hanging around, don't know code in looks like).

to make sure issue isn't due stdin/out/err being passed down, doing following in b

def _close_fds(): #workaround carstens bug     fd in [0, 1, 2]:         try:             os.close(fd)         except exception:             logger.info("file descriptor not open")  ... _close_fds() #make sure there no open file descriptors chile enherit pid = subprocess.popen([_root_path  + "something.py"]).pid ... 

is there better way this?

when starting process c b, , don't want inherit file handles, use following arguments in subprocess.popen;

  1. close_fds=true
  2. set stdin, stdout , stderr subprocess.pipe or subprocess.devnull.

the first closes file handles except stdin, stdout , stderr. arguments listed under (2) take care of those.